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

前端 未结 11 870
暗喜
暗喜 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:13

    You can use Aggregate to prepend each Char to the reversed string:

     "reverse me".Aggregate("", (acc, c) => c + acc);
    

提交回复
热议问题