コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【C#】配列やリストの要素を交互に連結する拡張メソッド

ソースコード

public static IEnumerable<T> MergeInterleaved<T>
(
    this IEnumerable<T> self,
    IEnumerable<T>      second
)
{
    return self
            .Zip( second, ( x, y ) => new[] { x, y } )
            .SelectMany( x => x )
        ;
}

参考サイト様