C#.net,Vb.net中的多重继承 [英] Multiple Inheritance in C#.net,Vb.net

查看:91
本文介绍了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> / *   ... * / } 



class B 继承自对象 通过 class A ,因此你有

对象<  -  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 {/*...*/}


class B inherits from Object via class A, hence you have

Object <- A <- B

this 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 B

and from this you do (not possible in c#)

class AB: A, B

So class AB inherits from two independent classes.

Very short, but you will find a lot about this with Google.


这篇关于C#.net,Vb.net中的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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