ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Is multiple inheritance possible in .NET and how?

user-image
تم إضافة السؤال من قبل Kashif Akhter , VP - Wing Head Application Development , National Bank of Pakistan
تاريخ النشر: 2013/04/16
mohamed sherif
من قبل mohamed sherif

no there is no multiple inhertinace in asp.net but you con over come on this proplem by using interface ,so you can inherite multiple interface

Ahmed Gamal
من قبل Ahmed Gamal , Senior Microsoft Dynamics AX Developer , Bi-Technologies

.NET Framework does not support multiple class inheritance directly (.Net support Multiple Interface Inheritance) read more http://stackoverflow.com/questions/3600881/how-many-classes-can-you-inherit-from-in-c http://stackoverflow.com/questions/178333/multiple-inheritance-in-c-sharp http://www.codeproject.com/Articles/10072/Simulated-Multiple-Inheritance-Pattern-for-C

Muhammed Effat Ahmed Afifi
من قبل Muhammed Effat Ahmed Afifi , Project Leader [Microsoft Business Unit] , Wipro Arabia Limited

in Fact The .NET Framework does not support multiple class inheritance directly (.Net support Multiple Interface Inheritance).
and this is why because the following :
1- "diamond problem" is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C.
If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C? For example, in the context of .NET GUI , a class Button may inherit from both classes Rectangle (for appearance) and Clickable (for functionality/input handling), and classes Rectangle and Clickable both inherit from the Object class.
Now if the equals method is called for a Button object and there is no such method in the Button class but there is an overridden equals method in both Rectangle and Clickable, which method should be eventually called???
2- Multiple implementation inheritance injects a lot of complexity into the implementation.
This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.

3- The number of places where MI is truly appropriate is actually quite small.
In many cases, multiple interface inheritance can get the job done instead.
In other cases, you may be able to use encapsulation and delegation.
If we were to add a slightly different construct, like mixins, would that actually be more powerful? If you need to read more about this visit : http://www.codeproject.com/Articles/17883/Multiple-Class-Inheritance-in-NET http://en.wikipedia.org/wiki/Diamond_problem#The_diamond_problem Note : don't forget to vote up my answer if it is useful for you .....

Panneer selvam xavier
من قبل Panneer selvam xavier , Supply Chain Analyst / Trainer , Infonet

Basically, it seemed that both the .NET and Java designers did not allow multiple inheritance because they reasoned that adding MI added too much complexity to the languages while providing too little benefit.
For a more fun and in-depth read, there are some articles available on the web with interviews of some of the language designers.
For example, for .NET, Chris Brumme (who worked at MS on the CLR) has explained the reasons why they decided not to: Different languages actually have different expectations for how MI works.
For example, how conflicts are resolved and whether duplicate bases are merged or redundant.
Before we can implement MI in the CLR, we have to do a survey of all the languages, figure out the common concepts, and decide how to express them in a language-neutral manner.
We would also have to decide whether MI belongs in the CLS and what this would mean for languages that don't want this concept (presumably VB.NET, for example).
Of course, that's the business we are in as a common language runtime, but we haven't got around to doing it for MI yet.
The number of places where MI is truly appropriate is actually quite small.
In many cases, multiple interface inheritance can get the job done instead.
In other cases, you may be able to use encapsulation and delegation.
If we were to add a slightly different construct, like mixins, would that actually be more powerful? Multiple implementation inheritance injects a lot of complexity into the implementation.
This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.

مستخدم محذوف‎
من قبل مستخدم محذوف‎

It differs from one language to the other , as far as i know it was supported in C but not in C#, but you can simulate multiple inheritance by using multiple interfaces instead.

Hazem Salama
من قبل Hazem Salama , Senior Member of Technical Staff , Verizon Communications

Multiple inheritance as a technique, yes it is possible but not out-of-the-box.
.Net allows only for single inheritance, you cannot specify more than one class, however, you are free to "implement" as many interfaces as you wish, which can buy you multiple inheritance but with some limitation.

Mohamed Hassan
من قبل Mohamed Hassan , Senior Application and Integration Developer , IBM

I think Yes .net has multiple inheritance

المزيد من الأسئلة المماثلة