Click here to Skip to main content
15,307,363 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
38. How can we achieve multiple inheritance in C#?
Posted
Comments
   
Questionnaire? Shame on you. You did not even bother to remove the number 38.
--SA

Only so-called weak form of multiple inheritance can be used.

Any interface can have unlimited number of parent interfaces in its inheritance list; any class (except System.Object) can have one and only one parent class in its inheritance list optionally followed by unlimited number of interfaces (to be implemented); any structure (struct) can implement unlimited number of interfaces as well.

If a parent class is not specified, it's the class System.Object, which is the common root type of all types (not just classes); this is the only class without a parent class.

[EDIT]

See also my past solution: Does C# support multiple inheritance?[^].

—SA
   
v3
   
BELOW IS CONCEPTUAL EXAMPLE.

Class derivedClass:baseClass ................................................
{ ...........................................................................
}............................................................................
.............................................................................

derivedClass is derived from baseClass.

Interface Inheritance example:

.............................................................................
private Class derivedClass:baseClass , InterfaceX , InterfaceY ..............
{ ......................................................................;;;;;
}......................................................................;;;;;;
.............................................................................

derivedClass is now derived from interfaces – InterfaceX, InterfaceY
Similarly a struct can be derived from any number of interfaces

......................................................................;;;;;;;
private struct childStruct:InterfaceX, InterfaceY ....................;;;;;;;
{ ...........................................................................
}...............
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900