I have the following class:
class Person
{
public string Name { get; set; }
public List<Person> Children { get; set; }
}
And I created an instance of this class, fox ex.
Person pers = new Person();
I can code foreach loops statically and store the Children in some list:
foreach (var item in pers.Children)
{
List<Person> r = item.Children;
foreach (var item2 in item.Children)
{
List<Person> k = item2.Children;
foreach (var item3 in item2.Children)
{
etc..
}
}
}
The problem is, how to code the foreach loops, if the "pers" has a children, and one of his children (pers.Children) also has a children. It's something like genealogical tree.
I mean, how to make it more dynamically? Because I don't know how the structure of the family can be.
Edit: I just want to show all the successors of one person. For example just names of his successors