.net - Access to parent's private properties through nested types in C# -
nested types in c# have ability access parent's private properties. there specific reason having language feature ? in opinion breaks encapsulation. if make nested type public, able expose private properties of parent class through it.
you would able - can nest class if you've got in same source file outer class in first place.
effectively nested class "owned" outer class, , trusted same extent other member of outer class. method in outer class expose private property - trust not to, because own code. likewise (the author of outer class) own code of nested class. if don't want break encapsulation in nested class, avoid writing code break encapsulation :)
Comments
Post a Comment