Reputation: 12663
If I instantiated five objects of Employee class: emp1,emp2...emp5 and put them in a listA of IList. Now if I create another IList listB which contains subset of listA, for example
IList<Employee> listB = listA.Take(3).ToList()
are Employee objects in listB refrence to the same Employee in the listA?
Thanks,
Upvotes: 0
Views: 185
Reputation: 415
I am not sure if you can do that; You will need to create a new list and add the items to it - which means it would be a copy. You think can also do that by using .ToList()
Upvotes: 0
Reputation: 71945
Yes, with the caveat that .Take
doesn't create an IList
. If you wrote listA.Take(3).ToList()
, then your description of the results (the list containing references to the same objects) would be accurate.
Upvotes: 3