using System.Collections.Generic;
public string Name { get; set; }
public Person Father { get; set; }
public Person Mother { get; set; }
public Person(string name, Person father, Person mother) {
public static void Main()
new Person("FFFF", null, null),
new Person("FM", null, null)
new Person("MFF", null, null),
new Person("MFMF", null, null),
new Person("MFMM", null, null)
new Person("MM", null, null)
var names = getNamesOfAllAncestors(pebbles);
Console.WriteLine("unbound result: {0}", string.Join(", ", names));
for (int i=0; i<=5; i++) {
names = getNamesOfAllAncestors(pebbles, i);
Console.WriteLine("result bound to {0} level{1} of ancestry: {2}", i, ((i==1) ? "" : "s"), string.Join(", ", names));
static List<string> getNamesOfAllAncestors(Person p, int? maxRecurseLevel=null, List<string> resultList = null) {
resultList = new List<string>();
if ((maxRecurseLevel == null) || (maxRecurseLevel.Value > 0)) {
if (maxRecurseLevel != null) {
getNamesOfAllAncestors(p.Mother, maxRecurseLevel, resultList);
getNamesOfAllAncestors(p.Father, maxRecurseLevel, resultList);