相关疑难解决方法(0)

我可以覆盖c#中的属性吗?怎么样?

我有这个基类:

abstract class Base
{
  public int x
  {
    get { throw new NotImplementedException(); }
  }
}
Run Code Online (Sandbox Code Playgroud)

以下的后代:

class Derived : Base
{
  public int x
  {
    get { //Actual Implementaion }
  }
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到这个警告,说Derived类的定义x是要隐藏Base的版本.是否可以覆盖c#like方法中的属性?

c# polymorphism inheritance overriding properties

68
推荐指数
3
解决办法
7万
查看次数

标签 统计

c# ×1

inheritance ×1

overriding ×1

polymorphism ×1

properties ×1