Enforcing parent-child relationship in C# and .Net

后端 未结 5 676
夕颜
夕颜 2020-12-14 23:29

Let\'s take the following two classes:

public class CollectionOfChildren
{
    public Child this[int index] { get; }
    public void Add(Child c);
}

public          


        
5条回答
  •  旧巷少年郎
    2020-12-15 00:03

    public class CollectionOfChildren
    {
        public Child this[int index] { get; }
        public void Add(Child c) {
            c.Parent = this;
            innerCollection.Add(c);
        }
    }
    
    public class Child
    {
        public CollectionOfChildren Parent { get; internal set; }
    }
    

提交回复
热议问题