Lazy LINQ and Enumerable Objects
Posted by: K. Scott Allen,
on 01 Oct 2008 |
View original | Bookmarked: 0 time(s)
Someone asked me why LINQ operators return an IEnumerable<T> instead of something more useful, like a List<T>. In other words, in the following code:List<Book> books = new List<Book>();
// ...
IEnumerable<Book> filteredBooks =
books.Where(book => book.Title.StartsWith("R"));
... we started with a List<Book>, so why isnt the Where operator smart enough to return a new List<Book>, or modify the existing list by removing books that dont match the Where...