Let’s say I have a parent/child-relationship ob objects and try to create a parent object inline (I’m not really sure that’s the right word). Is it possible to reference the created parent in its own creation code?
Parent = new Parent(
{
Name = "Parent",
Child= new Child(/*ReferenceToParent*/)
});
The only way round this would be for the
Parentconstructor to call theChildconstructor itself and pass inthis. Your object initializer (which is what I assume you’re trying to do) could then set other properties on the child:Then:
I would try to avoid this sort of relationship though – it can get increasingly tricky as time goes on.