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
write a program to find the biggest palindrome in the given string
Why do we override in c#?
What is the diff between the System.Array.CopyTo() and System.Array.Clone()?
Is list immutable in c#?
Are classes passed by reference in c#?
What does int32 mean?
To allow an element to be accessed using a unique key which .NET collection class is used ?
What is int32?
What is dataview c#?
Explain about c# language.
How do you type a null character?
List the two important objects of ado.net and also list the namespaces that are commonly used in ado.net to aid in connection to a database.
How to find type of variable?
What is alias in c#?
Why do we use dictionary in c#?