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.

  1. public List<string> Contexts
  2. {
  3.     get
  4.     {
  5.         var result = from u in SelectedUseCases
  6.                      from c in SelectedChannels
  7.                      from up in SelectedUserProfiles
  8.                      select string.Format("{0}-{1}-{2}", u.Value, c.Value, up.Value);
  9.  
  10.         return result.ToList();
  11.     }
  12. }

Simple and beautiful!