問候大家...如何從C#中的接口隱藏已實現屬性的set方法?
如果我有以下接口:
interface IMyInterface
{
int property { get; set; }
}
而下面的實現:
class MyClass : IMyInterface
{
// anything
}
我如何隱藏的實例的屬性set
方法MyClass
......換句話說,我不希望property
的set
方法公開,那有可能嗎?
這將是很容易做到與抽象類:
abstract class IMyInterface
{
int property { get; protected set; }
}
然後我只能set
的property
實現上面的抽象類的類內...
難道不會從界面中隱藏「屬性」嗎? – Girardi 2011-04-30 20:36:47
它會從界面中移除setter,你仍然可以讀取屬性。 – 2011-04-30 20:38:10
實現類中的setter將不可見,因爲它是在接口中輸入的nit。執行者**將**在實施的類中提供。 – 2011-04-30 20:47:00