Action greet = () => Console.WriteLine("Hello, world!"); greet(); // Output: Hello, world!
ListIn this example, an instance of the Action class is created with a generic parameter representing an integer. A lambda expression that prints the integer value is passed to the constructor of the Action class. The `ForEach` method of the `Listnumbers = new List { 1, 2, 3, 4, 5 }; Action printNumber = (number) => Console.WriteLine(number); numbers.ForEach(printNumber); // Output: 1 2 3 4 5