Reverse any Array using C# 4.0

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 2600
static void Main(string[] args)
{
int[] array = new int[5] { 10, 20, 30, 40, 50 };
IEnumerable<int> reversed = array.Reverse();
Console.WriteLine(String.Join(",", reversed));
Console.Read();
}


Result

50,40,30,20,10

static void Main(string[] args)
{
string[] array = new string[5] { "A", "B", "C", "D", "E" };
IEnumerable<string> reversed = array.Reverse();
Console.WriteLine(String.Join(",", reversed));
Console.Read();
}


Result

E,D,C,B,A

Comments or Responses

Login to post response