so, object initializers are all kinds of handy - especially if you're doing linq, where they're downright necessary - but I can't quite figure out this one:
public class Class1 {
public Class2 instance;
}
public class Class2 {
public Class1 parent;
}
using like this:
Class1 class1 = new Class1();
class1.instance = new Class2();
class1.parent = class1;
as an initializer:
Class1 class1 = new Class1() {
instance = new Class2() {
parent = class1
}
};
this doesn't work, class1 is supposedly an unassigned local variable. it gets even trickier in Linq when you are doing something like
select new Class1() { ...
it doesn't even have a name to refer to it by!
how do I get around this? can I simply not make nested references using object initializers?