Wednesday, November 04, 2009

How to Clone List in C#.net

To Copy List1 to List 2;

List List1;
//Create an array of strings
string[] arrStrList=new string[List1.Count];
//Copy the List to array of strings
List1.CopyTo(arrStrList);
//Define a new list
List List2= new List(List1.Count);
//Add array of strings to new list
List2.AddRange(arrStrList);

No comments: