How to merge Array

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

ad

I declare two string array:

string a1={"a", "b","c"};
string a2={"a", "b","c","d"};

Can I declare as
string a1={"a", "b","c"};
string a2=a1+{"d"};


The above is fail when compile, how can I do that?
 
ad said:
I declare two string array:

string a1={"a", "b","c"};
string a2={"a", "b","c","d"};

Can I declare as
string a1={"a", "b","c"};
string a2=a1+{"d"};

You can't. You'll have to include each item manually or write code using
Array.CopyTo to do it.

You might also elect to use a list structure instead. If you are using 1.x
use ArrayList, in 2.0 you can use List<string> and call the Add method to
add a new entry to the list.
 
Daniel O'Connell said:
You can't. You'll have to include each item manually or write code using
Array.CopyTo to do it.

You might also elect to use a list structure instead. If you are using 1.x
use ArrayList, in 2.0 you can use List<string>

and call the Add method to add a new entry to the list.
 
Mike Schilling said:
Did you mean to type "ArrayList<string> " or has List replaced ArrayListi
n 2.0 ?

It was List<string> as of beta 2. I havn't grabbed any of the more recent
builds so it could have changed, but I'd be surprised if it did.

It is Dictionary<T> instead of Hashtable now as well. The generic
collection's are a little better thought out.
 
It is Dictionary<T> instead of Hashtable now as well. The generic
collection's are a little better thought out.

Except SortedList, which is still called a list despite fundamentally
being a map :(
 
Daniel O'Connell said:
It was List<string> as of beta 2. I havn't grabbed any of the more recent
builds so it could have changed, but I'd be surprised if it did.

It is Dictionary<T> instead of Hashtable now as well. The generic
collection's are a little better thought out.

Interesting. Are the 2.0 class library docs available online?
 
Mike Schilling said:
Yes, I know how to do that. My memories of how to de-install the 1.0 beta
(re-format the hard disk, and no, I am not making this up) are still fresh
enough that I'd prefer not to.

I've removed beta 2 of 2.0 without problem before. And besides, aren't
you going to want to go to 2.0 at some point anyway?

If you want to just use the online version though, you can go to
http://msdn2.microsoft.com
 
Back
Top