In this snippet we will a simple program which reverse a string using Array.Reverse built in function using C#.NET.
Array.Reverse Method - Reverses the order of the elements in a one-dimensional Array or in a portion of the Array.
class ReverseString
{
static void Main()
{
Console.WriteLine(ReverseStr("DotNetMirror"));
Console.WriteLine(ReverseStr(".NET Mirror"));
Console.ReadLine();
}
public static string ReverseStr(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
}
Output:
rorriMteNtoD
rorriM TEN.