Cycle

public static IEnumerable<T> Cycle<T>(this IEnumerable<T> source)
{
    while (true)
    {
        foreach (var item in source)
        {
            yield return item;
        }
    }
}
Example:
var people = new[] { "Fred", "Bill", "Susan", "Amy" };
var teamNames = new[] { "Red", "Blue" };
var assignments = people.Zip(teamNames.Cycle(), (p, t) => new { Person = p, Team = t });
var teams =
    from a in assignments
    group a by a.Team into ts
    select new { TeamName = ts.Key, Members = from tm in ts select tm.Person };

Description

Repeats a sequence forever.

Details

Double click on the code to select all.

 

;