Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Reverse a string using LINQ in C#

We can use simple LINQ for reversing a string.

Remember to include
  1. using System.Linq;


  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4.  
  5.  
  6. namespace forgetCode
  7. {
  8. class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. Console.WriteLine("Enter the string to reverse :");
  13. string name = Console.ReadLine();
  14.  
  15. string output = new string(name.ToCharArray().Reverse().ToArray());
  16.  
  17.  
  18. Console.WriteLine(output);
  19.  
  20. }
  21. }
  22. }


Output:

Enter the string to reverse :
forget code

edoc tegrof