InsertBetween
Inserts an element in between every pair of consecutive elements.
/// Inserts the specified item in between each element in the input
/// collection.
/// The input collection.
/// The element to insert between each consecutive
/// pair of elements in the input collection.
/// A collection containing the original collection with the extra
/// element inserted. For example, new[] { 1, 2, 3 }.InsertBetween(0) returns
/// { 1, 0, 2, 0, 3 }.
public static IEnumerable InsertBetween(
this IEnumerable source, T extraElement)
{
return source.SelectMany(val => new[] { extraElement, val }).Skip(1);
}