using System; using System.Collections.Generic; Listnumbers = new List { 1, 2, 3, 4, 5 }; numbers.ForEach(number => Console.WriteLine(number));
using System; using System.Collections.Generic; class Person { public string Name { get; set; } public int Age { get; set; } } ListThis code creates a list of Person objects and initializes it with some values. The ForEach method is then used to print the name and age of each person in the list using a lambda expression. In conclusion, the System.Collections.Generic.List package is a part of the C# standard library that provides a generic collection class. The ForEach method is a member of this package that performs the same operation on each element of the list.people = new List { new Person { Name = "John", Age = 25 }, new Person { Name = "Jane", Age = 30 }, new Person { Name = "Bob", Age = 40 } }; people.ForEach(person => Console.WriteLine(person.Name + " is " + person.Age + " years old."));