In this snippet we will a simple program to reverse a string using Array.Reverse function in .NET.
Array.Reverse Method - Reverses the order of the elements in a one-dimensional Array or in a portion of the Array.
Reverse string using Array.Reverse function
|
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.
|
0 Comments:
Post a Comment