The ToList operator creates a List of type T from an input sequence of type T.
public static List<T> ToList<T>( this IEnumerable<T> source);
This operator takes an input sequence named source, of type T elements, and returns a List of type T elements.
ArgumentNullException is thrown if the source argument is null.
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program/*from w ww .ja v a 2 s . co m*/ { static void Main(string[] args) { string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"}; List<string> names = codeNames.ToList(); foreach (string name in names) Console.WriteLine(name); } }
In the code above, we use the array from the previous example.