Elegant way to combine multiple collections of elements?

前端 未结 11 2396
再見小時候
再見小時候 2020-12-05 03:36

Say I have an arbitrary number of collections, each containing objects of the same type (for example, List foo and List bar).

11条回答
  •  囚心锁ツ
    2020-12-05 04:12

    You can use Union as follows:

    var combined=foo.Union(bar).Union(baz)...
    

    This will remove identical elements, though, so if you have those, you might want to use Concat, instead.

提交回复
热议问题