Hi.
I've a problem with parent-child circular references.
Suppose have two classes, Person and Course:
--------------------------
public class Person{
public Person(string name, Course course){
this.name = name;
this.course = course;
}
string name;
public string Name { get{ return name;} }
Course course;
public Course Course { get{ return course;} }
}
public class Course{
public Course(string name, IList<Personpersons){
this.name = name;
this.persons = persons;
}
string name;
public string Name { get{ return name;} }
IList<Personpersons;
public Person Perons { get{ return persons;} }
}
--------------------------
How can I initialize a Person and a Course with their constructors?
Which class to create before?
Suppose that constructors check for not null.
Is this a correct solution (I intend for design, not for compile :-) )?
--------------------------
IList<Personpersons = new List<Person>();
Course math = new Course("Math", persons);
Person bill = new Person("Bill", math);
persons.Add(bill);
--------------------------
How can I solve this problem?
Matteo Migliore.