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

前端 未结 11 871
暗喜
暗喜 2021-02-02 16:01

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

11条回答
  •  [愿得一人]
    2021-02-02 16:10

    Variant with recursive lambda:

      var value = "reverse me";
      Func f = null; f = s => s.Length == 1 ? s : f(s.Substring(1)) + s[0]; 
      var reverseValue = f(value);
    

    LP, Dejan

提交回复
热议问题