Student for Life Student for Life - 3 months ago 16
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.

e.g.

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


and reversedValue will result in "em esrever"

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

Answer

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())
Comments