List attendees = new List();
foreach ...
// Error: \"There are too many target users in the email address array\"
// for more tha
There is a minor between Take
and GetRange
. Take will evaluate lazily until you force it to evaulate into ToList()
. This can change behavior.
Consider the pseudo code.
List myList = new List() {1,2,3,4,5,6};
IEnumerable otherList = myList.Take(3); // {1,2,3};
myList.RemoveRange(0,3);
// myList = {4, 5, 6}
// otherList = {4, 5, 6}
Now change this example to following code.
List myList = new List() {1,2,3,4,5,6};
IEnumerable otherList = myList.Take(3).ToList(); // {1,2,3};
myList.RemoveRange(0,3);
// myList = {4, 5, 6}
// otherList = {1, 2, 3}
Doing ToList()
can change the behavior of Take or GetRange depending upon what operations you are using next. It is always easier to use GetRange since it will not cause any unknown bugs.
Also GetRange is efficient.