About

Wednesday, September 25, 2019

.Net Core C# Revers String functionality without using .string.revers function 
: Interview questions 

Without using any .net revers string functionality. we can develop our own revers string function with using below code example


Example Code

static StringBuilder stringBuilder = new StringBuilder();
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Prasad KM");
           
            ReverseString("PrasadKM", 8);
            Console.WriteLine("First time string(PrasadKM) revers string :  " + stringBuilder.ToString());
         

string tempdata = stringBuilder.ToString();
            stringBuilder = new StringBuilder();

            ReverseString(tempdata, 8);
            Console.WriteLine("Second time string(MKdasarP) revers string :   " + stringBuilder.ToString());
            Console.Read();
        }

//Reflection Method
        static void ReverseString(string str, int len)
        {
            if (len <= 0)
                return;
            stringBuilder.Append(str[len - 1]);
            ReverseString(str, --len);
        }

//For each functionality
 static void ReverseString1(string str)
        {
           
            for (int i = str.Length-1; i <= str.Length; i--)
            {
                if (i < 0) break;
                stringBuilder.Append(str[i]);
            }
        }

OutPut


Conclusion : Without using .net string revers functionality, we can develep the our own revers string functionality with above code.

Please add your comments: