Example 1: C# program to reverse the given string
Program.cs
string s = "CODEAFT"; Console.WriteLine(s.Reverse().ToArray());
Output
codeaft@codeaft:~/csharp$ dotnet run WODNIWGNIDOK codeaft@codeaft:~/csharp$
Example 2: C# program to reverse the given string
Program.cs
string s = "CODEAFT"; char[] arr = s.ToCharArray(); Array.Reverse(arr); Console.WriteLine(arr);
Output
codeaft@codeaft:~/csharp$ dotnet run WODNIWGNIDOK codeaft@codeaft:~/csharp$
Example 3: C# program to reverse the given string
Program.cs
string r = "", s; s = "CODEAFT"; int len = s.Length - 1; while (len >= 0) { r = r + s[len]; len--; } Console.WriteLine(r);
Output
codeaft@codeaft:~/csharp$ dotnet run WODNIWGNIDOK codeaft@codeaft:~/csharp$
Comments and Reactions