C# provide a inbuilt method to reverse the given array in a efficient way. You can use this med and just pass the array into this function by reference and the array will converted in reverse order. The following example will help you to understand the use of array.reverse method.
using System;
namespace MyApp
{
class ArrayReverse
{
static void Main(string[] args)
{
string[] strArray = { "ten", "nine", "eight", "seven" };
Console.WriteLine("Before Reverse: ");
foreach(string str in strArray)
Console.Write(str + " ");
Array.Reverse(strArray);
Console.WriteLine("");
Console.WriteLine("After Reverse: ");
foreach (string str in strArray)
Console.Write(str + " ");
Console.ReadLine();
}
}
}
No comments:
Post a Comment