Can we join to array into a one

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have two arry with the same type, like

string[] FirstArray={"a", "a", "a"};
string[] FirstArray={"b", "b"};

How can I join these two arrays into one array?
 
i think you have to create a new array, if i remember right you can't
change an array size
 
There is no predefined way to join two arrays together (that I know
of), because there are several ways you might want to do that. Do you
want:

string[] joined = { "a", "a", "a", "b", "b" };

or

string[][] joined = { new string[] { "a", "a", "a" }, new string[] {
"b", "b" } };

or some other way of joining them?
 
Bruce said:
There is no predefined way to join two arrays together (that I know
of), because there are several ways you might want to do that. Do you
want:

string[] joined = { "a", "a", "a", "b", "b" };

or

string[][] joined = { new string[] { "a", "a", "a" }, new string[] {
"b", "b" } };

or some other way of joining them?

i think he wants the first
 
You can do the first in three lines:

string[] joinedArray = new string[firstArray.Length +
secondArray.Length];
firstArray.CopyTo(joinedArray, 0);
secondArray.CopyTo(joinedArray, firstArray.Length);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top