For some reason when I apply the reverse method, nothing changes.
public static string ReverseString(string word)
{
char[] myArray = word.ToCharArray();
myArray.Reverse();
string ans = string.Join("", myArray);
return ans;
}
Perhaps you're confusing the method you're using with the static Array.Reverse, which is indeed a void method?
Array.Reverse Method (Array)
The one you're using is a LINQ extension method of IEnumerable, whose reference you can find here:
Enumerable.Reverse Method (IEnumerable)
For your specific case though, I'd use this oneliner:
return new string(word.Reverse().ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With