How do you implement multiple inheritance in .NET?

Answer Posted / adavesh

Ofcourse using interfaces !!!

Its not just implementing 2 or more than one interfaces.
Its more than that. Lemme explain with a sample example

public namespace AccountManagement
{
public interface ICalcInterestOnLoan
{
double GetInterestOnLoan(double
dloanAmount);
}

public interface ICalcInterestOnDeposit
{
double GetInterestOnDeposit(double
dPrincipleAmount);
}

class LoanManager: ICalcInterestOnLoan
{
double GetInterestOnLoan(double dloanAmount)
{
//NOTE: All logic for calculating loan
interest goes here
}
}

class PrincipleManager: ICalcInterestOnDeposit
{
double GetInterestOnDeposit(double
dPrincipleAmount)
{
//NOTE: All logic for calculating
deposit interest goes here
}
}

public class AccountManager:ICalcInterestOnLoan,
ICalcInterestOnDeposit
{
ICalcInterestOnLoan oLoanInterest = new
LoanManager();
ICalcInterestOnDeposit oDepositInterest = new
PrincipleManager();
double GetInterestOnLoan(double dloanAmount)
{
return oLoanInterest.GetInterestOnLoan
(dLoanAmount);
}

double GetInterestOnDeposit(double
dPrincipleAmount)
{
return
oDepositInterest.GetInterestOnDeposit(dPrincipleAmount);
}
}

}//namespace ends


Here PrincipleManager & LoanManager are internal classes.
So, external assemblies do not know those classes. The
class AccountManager indirectly inherits the
functionalities of two classes & hence multiple inheritance
is achieved

Kote... got it ?

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of properties in c#?

730


Does a class need a constructor c#?

681


What is function c#?

673


Is system a class in c#?

650


What is lastindexof c#?

652


Why do we need singleton pattern in c#?

699


Explain About stateless and state full web service

750


What is the interface in c#?

716


What is session and cookies in c#?

733


How do I make a dll in c#?

694


What is the importance of closing an ado.net application?

677


if a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

713


List out two different types of errors in c#?

704


Explain publishers and subscribers in events.

718


Explain about Error handling and how this is done

724