Convert query result to list with ToList Operator in CSharp

Description

The following code shows how to convert query result to list with ToList Operator.

Example


using System;/*w w  w  . jav  a  2  s  .c  om*/
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
        List<string> names = presidents.ToList();
        foreach (string name in names)
            Console.WriteLine(name);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ