Q:

C# program to demonstrate the example of Linq Reverse() method

belongs to collection: C# LINQ Programs

0

C# program to demonstrate the example of Linq Reverse() method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

//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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# LINQ Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to reverse the list of cities using Lin... >>
<< C# program to demonstrate the example of Linq Then...