-2

Its written in books that through interface we can achieve multiple interface is it true or not?

Because in interface we only define the method not logic but in inheritance we access the method with its logic inside it.Which is not possible in interface we have to write interface method logic in derive class which i dont want na do then .How i can achieve Multiple inhertiance in C#.net?

5
  • 3
    Please invest some time and correct the errors in your question. Commented Aug 24, 2011 at 11:09
  • You can have a class implement multiple interfaces - but that's not multiple inheritance. C# does not support multiple inheritance (like C++ does). Commented Aug 24, 2011 at 11:10
  • Lookup extension methods (which can be used on interfaces). Commented Aug 24, 2011 at 11:11
  • possible duplicate of Should C# include multiple inheritance? Commented Aug 24, 2011 at 11:12
  • possible duplicate of How does using interfaces overcome the problem of multiple inheritance in C#? Commented Aug 24, 2011 at 11:13

2 Answers 2

2

It's not multiple inheritance because you only 'inherit' the contract when you implement an interface. You do not inherit any behavior (what you probably mean if you say 'multiple inheritance').

A short example:

public class MyClass : IComparable<MyClass>, IDisposable
{
    // Implement members from both interfaces.
    ...
}

The class MyClass behaves both as an IComparable<MyClass> and as an IDisposable.

Sign up to request clarification or add additional context in comments.

2 Comments

+1, or you could use extension methods defined on the interfaces if method body is to be the same, instead of duplicating code in each class.
Multiple inheritance means - inheriting properties and logic of two or more base class by derive class object.
0

c# doesn't support multiple inheritance .

Multiple Inheritance in C#

See the above link you will have clear understanding .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.