In the first case, the code is effectively converted by the compiler to
B b = new B(); A a = bA; a.AString = "aString"; b.BString = "bString";
Since you never assigned bA instance, you get an exception (in particular, since you never assigned bA , a is null, and therefore a.AString is going to throw a NullReferenceException ). The fact that code of the form new A... does not exist anywhere is a huge clue that an instance of a never created.
You can solve this problem by adding A = new A() to constructor B or by adding a field initializer to B._a .
In the second case, the code is converted by the compiler to
B b = new B(); A a = new A(); a.AString = "aString"; bA = a; b.BString = "bString";
This is normal, because now we have an instance of a .
jason
source share