Reputation: 8135
For example:
A a = new A(b);
B b = new B(a);
How can I use b
as a parameter in A
constructor when it's not existed, how can the compiler will know that b
will be created later?
Thank you.
Upvotes: 2
Views: 82
Reputation: 283614
Something along these lines:
class StrongReference<T> { public T Target; }
var rb = new StrongReference<B>;
A a = new A(rb);
rb.Target = new B(a);
Upvotes: 1
Reputation: 66389
You can't.
In A
class add public method like Init(B b)
and call it after you create the instance.
Upvotes: 7