Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过查看代码知道它是抽象还是继承_C#_C# 4.0_Inheritance_Abstract Class - Fatal编程技术网

C# 如何通过查看代码知道它是抽象还是继承

C# 如何通过查看代码知道它是抽象还是继承,c#,c#-4.0,inheritance,abstract-class,C#,C# 4.0,Inheritance,Abstract Class,我对c用于抽象和继承的方式有点困惑。 例如:抽象类如下所示 abstract class ShapesClass { abstract public int Area(); } class Square : ShapesClass //USES : { int side = 0; public Square(int n) { side = n; } // Area method is required to avoid

我对c用于抽象和继承的方式有点困惑。 例如:抽象类如下所示

abstract class ShapesClass
{
    abstract public int Area();
}


class Square : ShapesClass //USES :
{
    int side = 0;
    public Square(int n)
    {
        side = n;
    }
    // Area method is required to avoid 
    // a compile-time error. 
    public override int Area()
    {
        return side * side;
    }

    static void Main() 
    {
        Square sq = new Square(12);
        Console.WriteLine("Area of the square = {0}", sq.Area());
    }
}
一个看起来像

public class WorkItem
{
    private static int currentID;

    //Properties. 
    protected int ID { get; set; }
    protected string Title { get; set; }
    protected string Description { get; set; }
    protected TimeSpan jobLength { get; set; }

    public WorkItem()
    {
        ID = 0;
        Title = "Default title";
        Description = "Default description.";
        jobLength = new TimeSpan();
    }
}

public class ChangeRequest : WorkItem //This also uses :
{
    protected int originalItemID { get; set; }
}

那么如何区分呢?

由于不能实例化抽象类,因此需要子类实现这些方法。第二个示例是继承的简单示例


在本例中,ChangeRequest将WorkItem的所有属性和方法作为基类。如果要重写某些属性或方法,必须在Workitem类中将其声明为virtual

您可以浏览以下网站。你会明白的


看看父类,看看它是抽象的还是非抽象的。这不是一个/or的情况。两者都是继承的例子。在第一种情况下,基类是抽象的。在第二种情况下,基类不是抽象的。抽象类被清楚地声明为这样的:即:带有Abstract关键字。还有什么要说的?谢谢穆塞凡和J…这不是答案,只是一个链接。诸如此类的事情应该留作评论。OP并不是问这两者之间有什么区别。此外,此处不接受仅链接的答案,因为链接可能会中断,从而使您的答案无效。如果有什么区别的话,这个答案更适合作为一个评论