Listfruits = new List (); fruits.Add("apple"); fruits.Add("banana"); fruits.Add("orange"); Console.WriteLine(fruits[1]); // Output: banana
Listnumbers = new List () { 5, 2, 8, 3, 9 }; numbers.Sort(); foreach (int num in numbers) Console.WriteLine(num); // Output: 2 3 5 8 9
ListThis package library is part of the .NET framework and is located in the System.dll assembly.cities = new List () { "London", "Paris", "Madrid", "Rome", "Berlin" }; cities.Remove("Madrid"); foreach (string city in cities) Console.WriteLine(city); // Output: London Paris Rome Berlin