Gir*_*rdi 0 c# inheritance encapsulation interface
大家问候......
如果我有以下界面:
interface IMyInterface
{
int property { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下实施:
class MyClass : IMyInterface
{
// anything
}
Run Code Online (Sandbox Code Playgroud)
如何隐藏set属性的方法MyClass...换句话说,我不希望公开的set方法property,这可能吗?
使用抽象类很容易:
abstract class IMyInterface
{
int property { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)
然后,我只可能set在property实现上述的抽象类的类内...