【发布时间】:2023-08-25 02:17:01
【问题描述】:
大家好……
如果我有如下界面:
interface IMyInterface
{
int property { get; set; }
}
以及以下实现:
class MyClass : IMyInterface
{
// anything
}
如何从MyClass 的实例中隐藏set 的属性方法... 换句话说,我不希望property 的set 方法公开,这可能吗?
用抽象类很容易做到:
abstract class IMyInterface
{
int property { get; protected set; }
}
那我只能在实现上述抽象类的类中setproperty...
【问题讨论】:
标签: c# inheritance interface encapsulation