为什么在 C# 中不继承构造函数? [英] Why are constructors not inherited in C#?

查看:30
本文介绍了为什么在 C# 中不继承构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜我不明白关于 C# 继承的一些非常基础的东西.有没有大神指教一下?

I'm guessing there's something really basic about C# inheritance that I don't understand. Would someone please enlighten me?

推荐答案

有时,在子类化时,您想限制创建类实例所需的条件.

Sometimes, when subclassing, you want to restrict the conditions required to create an instance of the class.

让我举个例子.如果类确实继承了它们的超类构造函数,则所有类都将具有来自 Object 的无参数构造函数.显然这是不正确的.

Let me give you an example. If classes did inherit their superclass constructors, all classes would have the parameterless constructor from Object. Obviously that's not correct.

这篇关于为什么在 C# 中不继承构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆