Reverse the order of the elements in the entire List in CSharp
Description
The following code shows how to reverse the order of the elements in the entire List.
Example
/*w ww .j a va 2 s .c o m*/
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> myData = new List<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
myData.Add("E");
myData.Add("F");
myData.Add("G");
myData.Add("H");
myData.Add("newValue");
foreach(string myD in myData)
{
Console.WriteLine(myD);
}
myData.Reverse();
Console.WriteLine();
foreach(string myD in myData)
{
Console.WriteLine(myD);
}
}
}
The code above generates the following result.