The beauty of C# and Linq

Jan 26, 2010

Today I faced the following challenge to solve: return all possible combinations of three source collections.

We are using C# and with Linq it was just so easy.

public List<string> Contexts
{
    get
    {
        var result = from u in SelectedUseCases
                     from c in SelectedChannels
                     from up in SelectedUserProfiles
                     select string.Format("{0}-{1}-{2}", u.Value, c.Value, up.Value);
 
        return result.ToList();
    }
}

Simple and beautiful!