{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The ToList operator creates a List from a sequence.
EditMethod Signatures
public static List<TSource> ToList<TSource>(
this IEnumerable<TSource> source)EditExceptions
Throws an ArgumentNullException if
source is null.
EditPseudo-code
If
source is null, throw an ArgumentNullException.
Create a new
List<TSource>(source).
Return the new list.
EditLoop count
1. The constructor of
List<TSource> enumerates the sequence and adds it to the list.
EditSample code
// Open database context
MyDataContext db = new MyDataContext();
// Perform the query
var result = from p in db.Players select p;
// Get the List
List<Player> myList = result.
ToList();
// Iterate
foreach (Player currentPlayer in myList)
{
string value = currentPlayer.Name;
}