I want to reverse a string as given in the example.
string[] actor = new string[] { "amitabh", "abhishek", "jitendra", "Salman", "Aishwariya" };
var resultstring= actor.Reverse().Select(c => c.Reverse()).ToArray();
foreach(var m in resultstring)
{
//how to fetch this?
}
the output should be
ayirawhsia,namlas,ardnetij,kehsihba,hbatima
Most of the post mentioned on how to reverse without using built in reverse().
I need the result using only reverse built in function using linq. I am able to make it as shown in the above snippet but couldnt reach the end.
Can someone help me to fix this?
Change this line:
var resultstring = actor.Reverse().Select(c => c.Reverse()).ToArray();
To this:
var resultstring = actor.Reverse().Select(c => new string(c.Reverse().ToArray())).ToArray();
Of note here is the fact that when you called Reverse on the string it actually returned an IEnumerable<char> when you were probably expecting a string. No problem, the string constructor accepts an array of char which is what my tweak to your code does.
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