小编Tea*_*olf的帖子

Interleaved与LINQ合并?

我正在尝试使用LINQ.假设我有两个相同长度的集合:

var first = new string[] { "1", "2", "3" };
var second = new string[] { "a", "b", "c" };
Run Code Online (Sandbox Code Playgroud)

我想将这两个集合合并为一个,但是以交错的方式.因此,结果序列应为:

"1", "a", "2", "b", "3", "c"
Run Code Online (Sandbox Code Playgroud)

到目前为止,我想出的是一个Zip匿名类型和SelectMany:

var result = first.Zip( second, ( f, s ) => new { F = f, S = s } )
                  .SelectMany( fs => new string[] { fs.F, fs.S } );
Run Code Online (Sandbox Code Playgroud)

有没有人知道用LINQ实现这种交错合并的替代/简单方法?

c# linq

28
推荐指数
4
解决办法
5267
查看次数

标签 统计

c# ×1

linq ×1