When programming, the design of Object-related APIs may be problematic, so there is no solution yet.
The problem is as follows:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace consoleapplication
{
/// <Summary>
/// Fill in the corresponding content in notimplement's method/attribute to ensureProgramNo exception is thrown.
/// (That is, the parent attribute, addchild method, and removechild method .)
///
/// Other information cannot be modified.Code.
/// </Summary>
Class Program
{
Static void main (string [] ARGs)
{
Parent parenta = new parent ();
Parent parentb = new parent ();
Child child = new child ();
Parenta. addchild (child );
Child. Parent = parentb;
Assert (parenta. Children. Count = 0, parentb. Children. Count = 1, child. Parent = parentb );
Parenta. addchild (child );
Assert (parentb. Children. Count = 0, parenta. Children. Count = 1, child. Parent = parenta );
Child. Parent = NULL;
Assert (parentb. Children. Count = 0, parenta. Children. Count = 0, child. Parent = NULL );
}
Static void assert (Params bool [] values)
{
Foreach (VaR value in values)
{
If (value = false)
{
Throw new exception ();
}
}
}
}
Class Parent
{
Private list <child> _ children;
Public parent ()
{
This. _ Children = new list <child> ();
}
Public ilist <child> Children
{
Get
{
Return new system. Collections. objectmodel. readonlycollection <child> (this. _ children );
}
}
Public void addchild (child)
{
Throw new notimplementedexception ();
}
Public void removechild (child)
{
Throw new notimplementedexception ();
}
}
Class child
{
Private parent _ parent;
Public parent
{
Get
{
Throw new notimplementedexception ();
}
Set
{
Throw new notimplementedexception ();
}
}
}
}