c# - list.Take(100).ToList() vs. list.GetRange(0,100) -
list<attendeeinfo> attendees = new list<attendeeinfo>(); foreach ... // error: "there many target users in email address array" // more 100 attendees. take first 100 attendees only. if(attendees.count > 100) attendees = attendees.getrange(0,100); // or if(attendees.count > 100) attendees = attendees.take(100).tolist();
since work on list longer 100, , take first 100, obvious differences (evaluation strategy, possibility skip, throwing on errors) not interesting.
but perhaps shed light on "creates shallow copy of range of elements in source list" means. sounds expensive, more take, it?
the difference list.getrange
more efficient take(n).tolist()
since knows size of new list whereas linq methods don't know it's size.
so tolist
enumerates sequence , adds items new list doubling algorithm increasing backing array consecutively. list.getrange
can create proper list right initial size beforehand , uses array.copy
copy subset of source list new list [source].
Comments
Post a Comment