Hello...
What is the diferrence b/w string array and arraylist? How to conevert string array to arraylist and vice-versa?
Thanks a ton in advance!
:)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Zoran HorvatPosted Jul 29, 2011, 7:46 AM
string[] array = new string[1000];
ArrayList al = new ArrayList();
al.AddRange(array);
array = new string[al.Count];
int pos = 0;
foreach (object o in al)
array[pos++] = (string)o;
List
l.AddRange(array);
array = l.ToArray();
List
Difference between array and list is this. Array is a structure consisting of successive memory locations. List is dispersed in memory and consists of many arrays (if list is long). Main consequence is that you cannot add elements to array without reallocating complete array and without copying its complete contents (in general case). In particular case you can use Array.Resize
On the contrary, you can always insert and remove items from the List
Zoran