Is there idiomatic C# equivalent to C's comma operator?

前端 未结 7 1959
死守一世寂寞
死守一世寂寞 2020-12-14 07:18

I\'m using some functional stuff in C# and keep getting stuck on the fact that List.Add doesn\'t return the updated list.

In general, I\'d like to call

7条回答
  •  Happy的楠姐
    2020-12-14 08:02

    This is what Concat http://msdn.microsoft.com/en-us/library/vstudio/bb302894%28v=vs.100%29.aspx is for. Just wrap a single item in an array. Functional code should not mutate the original data. If performance is a concern, and this isn't good enough, then you'll no longer be using the functional paradigm.

    ((accum, data) => accum.Concat(new[]{data}))
    

提交回复
热议问题