using System.Collections.Generic; Listnumbers = new List (); numbers.Add(1); numbers.Add(2); numbers.Add(3); Console.WriteLine(numbers[0]); // Output: 1 Console.WriteLine(numbers.Count); // Output: 3
using System.Collections.Generic; class Program { static void Main(string[] args) { ListIn both examples, the package library used is System.Collections.Generic.people = new List (); people.Add(new Person("John", 25)); people.Add(new Person("Jane", 30)); people.Add(new Person("Jim", 40)); // Print out information about each person foreach (Person p in people) { Console.WriteLine($"{p.Name} is {p.Age} years old."); } } } class Person { public string Name { get; set; } public int Age { get; set; } public Person(string name, int age) { Name = name; Age = age; } }