I keep hearing that in .net 3.5 you should use IEnumerable over a List, but I can’t find any reference materials or articles that explain why it’s so much more proficient. Does
In .NET 3.5, using IEnumerable allows you to write methods with deferred execution, such as the following:
public class MyClass
{
private List
_listOne;
private List
_listTwo;
public IEnumerable
GetItems ()
{
foreach (int n in _listOne)
{
yield return n;
}
foreach (int n in _listTwo)
{
yield return n;
}
}
}
This allows you to combine the two lists without creating a new List
object.