using System;
using System.Linq;
class Program
{
static void Main(string[] args)
int[] numbers = { 1, 2, 3, 4, 5 };
var numberList = numbers.ToList();
foreach (var number in numberList)
Console.WriteLine(number);
}
/*
In this example, we have an array of integers called numbers. We use the ToList method to convert the
elements in the array into a list of integers.
The ToList method is useful when you want to convert a sequence into a list. It returns a List<T> that
contains the same elements as the original sequence.
In the code above, we call ToList on the numbers array and assign the result to the numberList variable.
The method returns a list that contains the same elements as the numbers array.
Note that the ToList method eagerly evaluates the entire sequence and returns a list that contains all the
elements. If you want to defer the evaluation, you can use the AsEnumerable method instead.
*/