C# extended function to reverse the given string.

Code Snippet

public static string ReverseString(this string s)
{
        char[] arr = s.ToCharArray();
        Array.Reverse(arr);
        return new string(arr);
}

Sample Usage

string str1 = "Hello World";
string str2= str1.ReverseString();

// str2 will be "dlroW olleH"
Categories : Programming, C#
Tags : Extended Function, String, Reverse


author's photo

Author : Si Thu

I am just a normal programmer. Cool, quiet and simple person. Love to write code without pressure. Most of the time, I am reading, writing, watching movie or surfing the web.

COMMENTS
blog comments powered by Disqus