覆盖属性不起作用

Fil*_*son 1 c#

我的类Ellipse应该从我的类继承Shape但是我收到此错误消息:

错误1'ConsoleApplication3.Ellipse'未实现继承的抽象成员'ConsoleApplication3.Shape.Perimeter.get'

我也收到了我隐藏的错误消息Area,一个属性Ellipse.

有人可以帮我吗?

我的形状类看起来像这样:

public abstract class Shape
{
    //Protected constructor
    protected Shape(double length, double width)
    {
        _length = length;
        _width = width;
    }


    private double _length;
    private double _width;

    public abstract double Area
    {
        get;
    }
Run Code Online (Sandbox Code Playgroud)

我的椭圆类是:

class Ellipse : Shape
{
    //Constructor
    public Ellipse(double length, double width)
        :base(length, width)
    {

    }

    //Egenskaper
    public override double Area
    {
        get
        {
            return Math.PI * Length * Width;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Pat*_*ald 5

您需要override在Ellipse类的Area和Perimeter属性上使用修饰符,例如

public override double Area { get; }

public override double Perimeter { get; }
Run Code Online (Sandbox Code Playgroud)

在Visual Studio中为您提示,将光标放在文本'Shape'(在椭圆类中)并按Ctrl+ ..这应该为您尚未实现的成员添加存根