C# program to reverse the list of cities using Linq

Here, we are going to learn how to reverse the list of cities using Linq in C#?
Submitted by Nidhi, on August 31, 2020

Here we will create a list of cities. Then reverse the list of cities using the Linq Reverse() method and print them on the console screen.


The source code to reverse the list of cities using Linq is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to reverse the list of cities using Linq.

using System;
using System.Linq;
using System.Collections.Generic;

class Program
    static void Main(string[] args)
        List<string> citys = new List<string>() {"Delhi","Ahmadabad","Agra","Mumbai"};


        Console.WriteLine("Reversed list of cities:");
        foreach (var item in citys)
            Console.Write(item + " ");


Reversed list of cities:
Mumbai Agra Ahmadabad Delhi
Press any key to continue . . .


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 the list of cities and then reverse the list using the Reverse() method and then print them using the "foreach" loop on the console screen.

C# LINQ Programs »


What's New (MCQs)

Comments and Discussions!

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.