System.Object 是基类 [英] System.Object being the base class

查看:20
本文介绍了System.Object 是基类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题对很多人来说可能很常见,我尝试了一个小时来理解这些事情,但没有得到正确的解释.

This question may be usual for many, i tried for an hour to understand the things but getting no proper explanation.

MSDN 说,System.Object 是 .NET Framework 中所有类的最终基类;它是类型层次结构的根.

当 C# 不允许多重继承时,我如何继承,比如说 A 类到 B 类.?因为所有的类,都已经继承自 System.Object 吧?这里我说的是正常的继承.

When C# doesn't allow multiple inheritance, how can I inherit, say a Class A to Class B. ? Because all classes, already inherits from System.Object right? Here I am talking about the normal inheritance.

Class A { --- }
Class B : A { --- }

请解开我的疑惑.谢谢.

Please, clear my doubts. Thank you.

更新:

再一次,我的疑问是,所有类都继承自 System.Object,那么 B 类将拥有 A 类和 System.Object.从我上面的例子

Again, My doubt is about, All classes inheriting from System.Object, then that would make Class B having Class A as well as System.Object. From my above example

推荐答案

正确,C# 只允许单继承.System.Object 类是由 A 类隐式继承的.所以 B 类是 A,也就是 System.Object.这由编译器负责,因此您无需明确声明 Class A : System.Object(尽管您可以根据需要这样做).

Correct, C# only allows single inheritence. The System.Object class is inherited implicitly by your Class A. So Class B is-a A, which is-a System.Object. This is taken care of by the compiler so you don't need to explicitly say that Class A : System.Object (though you can if you want).

这篇关于System.Object 是基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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