草庐IT

IsBeaten

全部标签

c# - 如何在 C# 中实现选择性属性可见性?

我们能否使类的属性对public可见,但只能由某些特定类修改?例如,//thisisthepropertyholderpublicclassChild{publicboolIsBeaten{get;set;}}//thisisthemodifierwhichcansetthepropertyofChildinstancepublicclassFather{publicvoidBeatChild(Childc){c.IsBeaten=true;//shouldbenoexception}}//thisistheobserverwhichcangetthepropertybutcannot