+ 1

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.

16th Mar 2020, 5:46 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
6 ответов
+ 5
Here is another approach using built in method Array.Reverse https://code.sololearn.com/c3FGepbX71qC/#cs
16th Mar 2020, 8:16 AM
Viktor Sokolov
Viktor Sokolov - avatar
+ 4
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
16th Mar 2020, 6:56 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 4
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.
16th Mar 2020, 8:50 AM
A͢J
A͢J - avatar
+ 3
Yes we can do like this: String str = "Anant"; String newstr = ""; for(int I = (str.Length - 1); I >=0; I--) { newstr = newstr + str[I]; } https://code.sololearn.com/cMaamAxIcNNT/?ref=app
16th Mar 2020, 5:48 AM
A͢J
A͢J - avatar
+ 3
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); }
16th Mar 2020, 8:35 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 2
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.
16th Mar 2020, 5:49 AM
Avinesh
Avinesh - avatar