473,228 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Why Doesn't c# support Multiple Inheritance ?

There are a number of reasons we don't implement Multiple Implementation
Inheritance directly. (As you know, we support Multiple Interface

However, I should point out that it's possible for compilers to create MI
for their types inside the CLR. There are a few rough edges if you go down
this path: the result is unverifiable, there is no interop with other
languages via the CLS, and in V1 and V1.1 you may run into deadlocks with the
OS loader lock. (We're fixing that last problem, but the first two problems
remain). The technique is to generate some VTables in RVA-based static
fields. In order to deposit the addresses of managed methods (which probably
haven't been JITted yet), you use the VTFixup construct. This construct is a
table of triplets. The triplets consist of a token to a managed method, an
address in your image that should be fixed up (in this case, a slot of the
VTable you are creating in the RVA-based static), and some flags. The
possible flags are described in corhdr.h and they allow you to specify 32-
vs. 64-bit pointer sizes, control over virtual behavior, and whether some
reverse-PInvoke behavior should be applied in the form of a thunk that
eventually dispatches to the managed method. If we are performing an
unmanaged->managed transition, you also have some control over which
AppDomain should be selected for us to dispatch the call. However, one of
these options (COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN) doesn't exist in
V1. We added it in V1.1.

There are several reasons we haven't provided a baked-in, verifiable,
CLS-compliant version of multiple implementation inheritance:

1. 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.

2. 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?

3. 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's not at all clear that this feature would pay for itself. It's something
we are often asked about. It's something we haven't done due diligence on.
But my gut tells me that, after we've done a deep examination, we'll still
decide to leave the feature unimplemented.
please post your doubts and help me to explore ny knowledge.
Feb 15 '06 #1
1 2938
vinoraja <vi******@discussions.microsoft.com> wrote:


Note that this post was taken verbatim from a post made by Chris
Brumme. It's available in the C# FAQ at


and was also at

It's always good to include attributions rather than passing off an
answer as your own...

Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
by: mmu2643 | last post by:
Hi, I had a question regarding multiple inheritance. class B1{ public: int a; };
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
by: Paul McGuire | last post by:
On May 25, 8:37am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.