Sai Kumar Koona
Write a program in C# Sharp to reverse a string?

We need to write a simple C# code to demonstrate a reversing the given input string at runtime. Below is the code snippet to achive this.

  1. class Program
  2. {
  3. internal static void ReverseString(string str)
  4. {
  5. char[] charArray = str.ToCharArray();
  6. for (int i = 0, j = str.Length - 1; i < j; i++, j--)
  7. {
  8. charArray[i] = str[j];
  9. charArray[j] = str[i];
  10. }
  11. string reversedstring = new string(charArray);
  12. Console.WriteLine(reversedstring);
  13. }
  14. static void Main(string[] args)
  15. {
  16. ReverseString(args[0]);
  17. Console.ReadKey();
  18. }
  19. }
By Sai Kumar Koona in .NET Core on Dec 24 2021
  • Ashok Kumawat
    Dec, 2021 27

    In more simple way we can revese string like this.

    1. static void ReverseString(string str)
    2. {
    3. string nStr = string.Empty;
    4. foreach (var item in str)
    5. {
    6. nStr = item + nStr;
    7. }
    8. Console.WriteLine(nStr);
    9. }

    • 4
  • Paw Kor
    Jul, 2022 11

    Public static void Program() {string input =Console.ReadLine();string Reverse(string str) {string result = string.Empty;var x = str.ToCharArray();for(int i = x.Length - 1; i >=0 ;i--){result = x[i] ;} return result;} Console.WriteLine(Reverse(input)); }

    • 0
  • Vishal Yelve
    Jul, 2022 8

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

    • 0
  • Hisham Shahid
    Jan, 2022 3

    1. public static string ReverseString(string input)
    2. {
    3. string output = "";
    4. for (int i = input.Length-1; i >= 0; i--)
    5. {
    6. output+=input[i];
    7. }
    8. return output;
    9. }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS