Copying a single dimension array into a structure array

Hi, I've got a structure with multiple strings. I want to copy a string array into the structure array. Any suggestions? I don't want the string copied into all elements of the structure array, just the one I specify.

protected struct my_struct
{
    protected string string1;
    protected string string2;
    protected string string3;
}

protected void doSomeWork()
{
    string[] myStringArray = new string [5];
    my_struct[] myStructureArray = new my_struct[5];

    myStringArray[0] = "a";
    myStringArray[1] = "b";
    myStringArray[2] = "c";
    myStringArray[3] = "d";
    myStringArray[4] = "e";

//Here's basically where I'm stuck!
    Array.Copy(myStringArray, myStructArray.string1, 1);
}

Any help would be appreciated. I have a feeling this is something simple that I'm missing.
SoCalChrisAsked:
Who is Participating?
 
AaronReamsConnect With a Mentor Commented:
Here's the other option... but you're copying an array to an array, not consolidating an array to one string.  is that what you want?

protected struct my_struct
{
    public string[] string1;
    public string[] string2;
    public string[] string3;
}

string[] myStringArray = new string [5];
my_struct[] myStructArray = new my_struct[5];
myStringArray[0] = "a";
myStringArray[1] = "b";
myStringArray[2] = "c";
myStringArray[3] = "d";
myStringArray[4] = "e";

myStructArray[0].string1 = new string[5];

//Here's basically where I'm stuck!
Array.Copy(myStringArray, myStructArray[0].string1, 1);

0
 
AaronReamsCommented:
Here's one way to do it...

string[] myStringArray = new string [5];
myStringArray[0] = "a";
myStringArray[1] = "b";
myStringArray[2] = "c";
myStringArray[3] = "d";
myStringArray[4] = "e";

my_struct myStructArray = new my_struct;
for(int i=0; i<5; i++)
     myStructArray.string1+=myStringArray[i];
0
 
AaronReamsCommented:
also the members of your struct need to be public.
0
 
SoCalChrisAuthor Commented:
Do you know how to do this without having to loop through each array item?
0
All Courses

From novice to tech pro — start learning today.