这里使用哪个班级? C#

时间:2016-02-01 22:17:41

标签: c# instantiation

如果我是基类" Base"和派生类"派生"然后哪一个好吗?

<Error>
    <Message>
        No HTTP resource was found that matches the request URI 'http://example.com/api/admin/echo'.
    </Message>
    <MessageDetail>
    No type was found that matches the controller named 'admin'.
    </MessageDetail>
</Error>

(上面两行很好)

Base b = new Base();
Derived d = new Derived();

他们有意义吗?

1 个答案:

答案 0 :(得分:1)

@ Zuzlx的评论是现场评论:

  

所有奶牛都是动物,但不是所有的奶牛都是奶牛。

Base替换为Animal,将Derived替换为Cow,它将变得更加清晰:

Animal a = new Cow();  // This works since a cow is always an animal.
Cow c = new Animal();  // Just won't work.