using toarray method
ToArray is a Linq extension method and it converts any IEnumerable type to an array. In the example given below the LINQ query result is of IEnumerable type and we use Toarray to convert the query result into an array. After converting the query to an array, we store it in memory. The ToArray extension method creates a buffer array to which the elements query result are copied. When we call ToArray LINQ query is executed immediately. The example discussed is based on the SalesOrderManagement domain model.
Example for Convert LINQ query results into an array with ToArray method
SalesDBDataContext dataContext = new SalesDBDataContext();
var custQuery = from cust in dataContext.Customers
select cust;
Customer[] qArray = custQuery.ToArray();
foreach (var pair in qArray)
{
Console.WriteLine(pair.CustomerId);
}