using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // Initialize List of integers Listnumbers = new List () { 1, 2, 3, 4, 5 }; // Add new numbers to the List numbers.Add(6); numbers.Add(7); // Remove a number from the List numbers.Remove(4); // Print contents of the List foreach (int number in numbers) { Console.WriteLine(number); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // Initialize List of strings ListPackage Library: .NET Framework Class Library.words = new List () { "hello", "world", "from", "OpenAI" }; // Print contents of the List using ForEach method and lambda expression words.ForEach(word => Console.WriteLine(word)); } }