In this program, you’ll learn to remove last item of an array in C# using C# Console Application. You’ll learn to display the mutated array on Console.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class Program { static void Main(string[] args) { string[] numbers = { "A", "B", "C", "D","E" }; Console.WriteLine("Before remove"); foreach (var item in numbers) { Console.Write(item+" "); } //remove last item numbers = numbers.Take(numbers.Count() - 1).ToArray(); Console.WriteLine("\nAfter remove"); foreach (var item in numbers) { Console.Write(item + " "); } Console.ReadLine(); } } |
Output: