I have to create a class in C#, call it Class1. This class must contain an enum field, called Flag. Flag has 4 possible values, say A,B,C,D. An instance of Class1 can contain another instance of Class1 where the state of Flag is different from A.
My question is: how to formulate the condition that the state of Flag in the sub-instance must be different from A?
Mark your Class1 "subinstance" as private and make it accessible only through a property. In the property setter, check that the value which is set has the flag different from the one of the parent. Be careful, if the parent Class1 flag must always be different from the child, then you also have to add a check when setting the parent flag.