Introduction : In this tutorial we will see how to reverse the given string word or sentence using C# and VB.NET
There are many ways to reverse of the sting. And I am showing one of them. This code sample is used to display reverse of the given string. In this code example I have used Reverse() method of array class.
C# Example code sampleusing System;
namespace DotNetSpark.Tutorials
{
class DotNetSpark
{
static void Main(string[] args)
{
// Declare string ;
string strValue = "DotNetSpark";
// store the string in character array
char[] arrResult = strValue.ToCharArray();
// reverse the string using Array.Reverse() method
Array.Reverse(arrResult);
// Display reverse string
Console.WriteLine(new string(arrResult));
Console.ReadLine();
}
}
}
Output:
krapSteNtoD
VB.NET code sampleNamespace DotNetSpark.Tutorials
Class DotNetSpark
Private Shared Sub Main(args As String())
' Declare string ;
Dim strValue As String = "DotNetSpark"
' store the string in character array
Dim arrResult As Char() = strValue.ToCharArray()
' reverse the string using Array.Reverse() method
Array.Reverse(arrResult)
' Display reverse string
Console.WriteLine(New String(arrResult))
Console.ReadLine()
End Sub
End Class
End Namespace
Output:
krapSteNtoD |