Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 292 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to copy a list to a new list, or retrieve list by value in c#

#1
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?
Reply

#2
Have you tried Cloning (Clone()) each item and adding the clone to a new collection?
Reply

#3
List<MyType> copy = new List<MyType>(original);

Reply

#4
If you are using .NET 3.5, the resulting array can have ToList() called on it.
Reply

#5
Just create a new `List` and use the appropriate constructor:

IList<Obj> newList = new List<Obj>(oldList);
Reply

#6
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);
Reply

#7
> 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();
Reply

#8
It seems if you have a list of references, the list

List<Object> list2 = new List<Object>(list1);

does not work.

This should solve your problem:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through