create list in csharp code example
Example 1: create List c#
using System.Collections.Generic
//type is your data type (Ej. int, string, double, bool...)
List<type> newList = new List<type>();
Example 2: csharp list
List<int> numbers = new List<int>() { 1, 2, 5, 7, 8, 10 };
Console.WriteLine(numbers[0]); // prints 1
Console.WriteLine(numbers[1]); // prints 2
Console.WriteLine(numbers[2]); // prints 5
Console.WriteLine(numbers[3]); // prints 7
// using foreach LINQ method
numbers.ForEach(num => Console.WriteLine(num + ", "));//prints 1, 2, 5, 7, 8, 10,
// using for loop
for(int i = 0; i < numbers.Count; i++)
Console.WriteLine(numbers[i]);