| using System;
using System.Collections.Generic;
using System.Linq;
public class Example1{
public static void Main(){
// A collection of all possible combination of female-male pairs
IEnumerable<Person> males = Person.SomePersons
.Where(p => p.Sex == Sex.Male);
IEnumerable<Person> females = Person.SomePersons
.Where(p => p.Sex == Sex.Female);
var pairs = males // SelectMany flattens the nested sequences
.SelectMany(m => females
.Select(f => new{First=f, Second=m}));
foreach(var pair in pairs)
Console.WriteLine("{0} <-> {1}", pair.First, pair.Second);
}
} |