abstract 修饰符可以和类、方法、属性、索引器及事件一起使用。在类声明中使用 abstract 修饰符以指示某个类只能是其他类的基类。标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的类来实现。

在此例中,类 Square 必须提供 Area 的实现,因为它派生自 ShapesClass

 CopyCode image复制代码
        abstract class ShapesClass
{
    abstract public int Area();
}
class Square : ShapesClass
{
    int x, y;
    // Not providing an Area method results
    // in a compile-time error.
    public override int Area()
    {
        return x * y;
    }
}

有关抽象类的更多信息,请参见抽象类、密封类及类成员(C# 编程指南)

Expand 图像备注

Expand 图像示例

Expand 图像注释

Expand 图像C# 语言规范

Expand image请参见