The source code to demonstrate the Linq Reverse() method, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to demonstrate Linq Reverse() method.
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[] { 20,50,40,39,43,23,45,17,38};
IEnumerable<int> result = numbers.Reverse();
Console.WriteLine("Reversed array:");
foreach (var item in result)
{
Console.Write(item + " ");
}
Console.WriteLine();
}
}
Output:
Reversed array:
38 17 45 23 43 39 40 50 20
Press any key to continue . . .
Explanation:
In the above program, we created a class Demo that contains the Main() method. The Main() method is the entry point for the program.
In the Main() method, we created an array of integers and then reverse the array using the Reverse() method and then print them using the "foreach" loop on the console screen.
Program:
The source code to demonstrate the Linq Reverse() method, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a class Demo that contains the Main() method. The Main() method is the entry point for the program.
In the Main() method, we created an array of integers and then reverse the array using the Reverse() method and then print them using the "foreach" loop on the console screen.