Is it a C # compiler or CLR that prohibits multiple inheritance

Exactly as the name says.

Is this a restriction set by the C # compiler, or is the CLR fundamentally forbidding it?

+6
source share
3 answers

AND.

C #, which is not directly related to the CLR (i.e. Mono AOT), does not allow multiple inheritance.

A system such as the CLR, which supports languages ​​other than C #, also does not support multiple inheritance.

+5
source

CLR prohibits this. If it was just a compiler, you can use Reflection to overcome it at runtime. Multiple inheritance (except for the interface) is in direct violation of the CLR type system.

+1
source

There are at least three levels:

  • .NET library: the .NET type system does not support it (look at the Type.BaseType property ... This is a Type , not Type[] , so not even future support)

  • IL Language: I do not know, but probably not, otherwise the Type type would be different (because the IL language was built along with everything else)

  • C # compiler: no, because C # is the main choice of the .NET language and should show everything (almost everything) that can be done in .NET without creating too many constructs that cannot be emulated through ". NETWORK. Syntactic sugar, such like LINQ and object initializers, this is one (ease of emulation in other languages), a parallel type system :-)

+1
source

Source: https://habr.com/ru/post/951229/


All Articles