Student for Life Student for Life - 1 year ago 104
C# Question

Can you reverse order a string in one line with LINQ or a LAMBDA expression

Not that I would want to use this practically (for many reasons) but out of strict curiousity I would like to know if there is a way to reverse order a string using LINQ and/or LAMBDA expressions in one line of code, without utilising any framework "Reverse" methods.


string value = "reverse me";
string reversedValue = (....);

and reversedValue will result in "em esrever"

Clearly an impractical problem/solution I know this, so don't worry it's strictly a curiosity question around the LINQ/LAMBDA construct.

Answer Source

I don't see a practical use for this but just for the sake of fun:

new string(Enumerable.Range(1, input.Length).Select(i => input[input.Length - i]).ToArray())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download