I noticed in c# there is a method for Lists: CopyTo -> that copies to arrays, is there a nicer way to copy to a new list? problem is, I want to retrieve the list by value to be able to remove items before displaying them, i dont want the original list to be modified, that too doesnt seem to be easily attainable, any ideas?
A:
Have you tried Cloning (Clone()) each item and adding the clone to a new collection?
Chuck Conway
2009-11-24 23:16:19
Just what I was going to say
Preet Sangha
2009-11-24 23:18:43
A:
If you are using .NET 3.5, the resulting array can have ToList() called on it.
John Buchanan
2009-11-24 23:17:04
+1
A:
Just create a new List
and use the appropriate constructor:
IList<Obj> newList = new List<Obj>(oldList);
bruno conde
2009-11-24 23:17:46
+1
A:
I think this will work. Passing a list to the constructor of a new list.
List<string> list1 = new List<string>();
List<string> list2 = new List<string>(list1);
Andy West
2009-11-24 23:18:31
+2
A:
I want to retrieve the list by value to be able to remove items before displaying them,
var newlist = oldList.Where(<specify condition here>).ToList();
Jimmy
2009-11-24 23:21:39