A colleague and I are having a bit of an argument over multiple inheritance. I'm saying it's not supported and he's saying it is. So, I thought that I'd ask the brainy bunch on the net.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
As an additional suggestion to what has been suggested, another clever way to provide functionality similar to multiple inheritance is implement multiple interfaces BUT then to provide extension methods on these interfaces. This is called mixins. It's not a real solution but it sometimes handles the issues that would prompt you to want to perform multiple inheritance.
Like Java (which is what C# was indirectly derived from), C# does not support multiple inhertance.
Which is to say that class data (member variables and properties) can only be inherited from a single parent base class. Class behavior (member methods), on the other hand, can be inherited from multiple parent base interfaces.
Some experts, notably Bertrand Meyer (considered by some to be one of the fathers of object-oreiented programming), think that this disqualifies C# (and Java, and all the rest) from being a "true" object-oriented language.
Nope, use interfaces instead! ^.^
You cannot do multiple inheritance in C# till 3.5. I dont know how it works out on 4.0 since I have not looked at it, but @tbischel has posted a link which I need to read.
C# allows you to do "multiple-implementations" via interfaces which is quite different to "multiple-inheritance"
So, you cannot do:
But, you can do:
HTH
Sorry, you cannot inherit from
multiple classes
. You may use interfaces or a combination ofone class and interface(s)
, where interface(s) should be followed by class name in the signature.Possible ways to inherit:
This is not legal:
Simulated Multiple Inheritance Pattern
http://www.codeproject.com/KB/architecture/smip.aspx