クラス内のコードは示されていないので、私はあなたが何をしようとしていたかをいくつか仮定する必要があります。あなたのコードからわかるように、Content
ニーズMaster
とは。Master
なしでは生きていけませんContent
。
私があなたのために作った解決策で、あなたは以下をすることができます:
void Main()
{
Master M1 = new Master(); // content instantiated implicitly
Master M2 = new Content().master; // master instantiated implicitly
}
したがって、Master
とContent
をインスタンス化するか、またはその逆を行うことができます。aをインスタンス化するContent
と、Master
は暗黙的にインスタンス化されます。
選択した選択肢に関係なく、対応する他のオブジェクトは常にインスタンス化され、プロパティ変数を介して使用できます。
この例のクラスは次のように定義されています。
internal class Content {
internal Master master { get; set; }
internal Content(Master pmaster) {
master=pmaster;
}
internal Content() {
master = new Master() { content = this };
}
}
public class Master {
internal Content content { get; set; }
internal Master() {
content = new Content(this);
}
// this is optional and can be omitted, if not needed:
internal Master(Content pcontent) {
content = pcontent;
}
}
私はあなたがあなたに質問した構造を可能な限り忠実に保ちましたが、あなたは今や余分な柔軟性を持っていることに注意してください。