C#.net,Vb.net中的多重继承 [英] Multiple Inheritance in C#.net,Vb.net
问题描述
MSDN说,System.Object是.NET Framework中所有类的最终基类;它是类型层次结构的根。
当C#不允许多重继承时,我怎样才能继承,比如说A类到B类?因为所有类,都已经从System.Object继承了吗?我在这里谈论正常的继承。
A级{---}
B级:A {---}
请清除疑惑......
继承自System.Object的所有类,然后使类B也具有A类as System.Object。
当你写:
类 B:{{span class =code-comment> / * ... * / }
classB
继承自对象
通过 classA
,因此你有对象< - A< -B这不是多重继承。
非常简短:
从CPallini读取解决方案#1。他解释了为什么你所描述的情况不是多重继承。
为了让你了解多重继承是什么:
你有例如两个班级
<前一个=文字>一个班级A
班级B你可以这样做(c#中不可能)
AB类:A,B所以AB类继承自两个独立的类。
很短,但你会发现很多关于谷歌的事情。
MSDN says, System.Object is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.
When C# doesnt 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 the doubts...
All classes inheriting from System.Object, then that would make Class B having Class A as well as System.Object.
When you write:
class B : A {/*...*/}
classB
inherits fromObject
via classA
, hence you haveObject <- A <- Bthis is not multiple inheritance.
In very short:
Read Solution #1 from CPallini. He is explaining why the situation you described is not multiple inheritance.
To give you a basic idea what multiple inheritance is:
You have e.g. two classes
class A class Band from this you do (not possible in c#)
class AB: A, BSo class AB inherits from two independent classes.
Very short, but you will find a lot about this with Google.
这篇关于C#.net,Vb.net中的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!