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

the c# keyword .int. Maps to which .net type?

750


What is an inheritance ?Give an example in which inheritance is used?

528


Is c# front end or back end?

513


How can you prevent escaping on backslashes in C# with string definitions?

697


What is the difference between static and constant variables?

543






What is difference between constants and read-only?

448


If a method's return type is void, can you use a return keyword in the method?

541


What is type safe code?

476


What is a datacontract?

482


Define multicast c# delegate?

560


What is eager loading in c#?

469


what is the Difference between the public and private ?

519


Can a struct have a default constructor (a constructor without parameters) or a destructor in c#?

518


What is the use of protected in c#?

497


What is the difference between internal and protected in c#?

437