Sunday, 10 February 2013

String Reverse in C# using LINQ

String Reverse in C#


String reverse using LINQ in C#
Reversing a string :String class has reverse method,
this Reverse method returns IEnumerable<char> so you need to convert it to an array of character.
String constructor accepts  array of characters as input param.

static String StringReverse()
      {
          String str = "Hello World!";
          Console.WriteLine(str);
          str = new string(str.Reverse().ToArray());
          Console.WriteLine(str);
           return str;
      }

Output:  !dlroW olleH

Tags:String Reverse in C# using LINQ, String.Reverse(),convert characters to an array,convert an array of characters to String,String reverse using LINQ,Reverse.ToArray()

No comments:

Post a Comment