How do I turn a string backwards using c# ? | Sololearn: Learn to code for FREE!


How do I turn a string backwards using c# ?

Is it possible to turn a string backwards ?.Please if there is can you show me.

3/16/2020 5:46:43 AM

Joseph Oritseweyinmi

6 Answers

New Answer


Here is another approach using built in method Array.Reverse


Just like every programming language C# has a lot of ways to reverse a string. Here's a hint, Take a string, use .ToCharArray() method of string and convert string to character array then use Array.Reverse() to reverse the array and then again convert it to string. cheers


0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ Stack by default push element from backward so definetly it will give in reverse order.


Yes we can do like this: String str = "Anant"; String newstr = ""; for(int I = (str.Length - 1); I >=0; I--) { newstr = newstr + str[I]; }


Joseph Oritseweyinmi you can use Stack if you want to do differently Stack myStack = new Stack(); myStack.Push(1); myStack.Push(2); myStack.Push(3); myStack.Push(4); foreach(var item in myStack){ Console.WriteLine(item); }


Use arrayLength-1 as the starting point and iterate till index 0 to get the result. A simple for loop will do the job. Show the community your attempt so that it becomes easy to make corrections.