ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn about the Linq Reverse() method and C# implementation.
Submitted by Nidhi, on August 31, 2020

Here we will create an array of integers. Then reverse the array using Linq Reverse() method and print the reversed array 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.

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

C# LINQ Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.