Q:

C# program to reverse the list of cities using Linq

belongs to collection: C# LINQ Programs

0

C# program to reverse the list of cities using Linq

All Answers

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

Program:

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"};

        citys.Reverse();

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

Output:

Reversed list of cities:
Mumbai Agra Ahmadabad Delhi
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 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.

 

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 demonstrate the example of Linq Aggr... >>
<< C# program to demonstrate the example of Linq Reve...