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 is called method in c#?

596


What is Asynchronous call and how it can be implemented using delegates?

656


Why should you override the tostring() method?

679


Are there constructors in c sharp?

650


Differentiate between method overriding from method overloading with its functionality?

615






What is arraylist?

601


How to exclude a property from xml serialization?

647


how to stored and retrive video in Sql server using asp.net c#......?

612


How is a loop recorder monitored?

601


Is c# good for beginners?

556


What do you mean by default constructor?

695


Why c# is called c sharp?

546


What is a c# delegate?

698


What is the difference between method and constructor in c#?

552


In which format you can pass the value in the sleep function?

624