-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?

Ronald Wildenberg
  • 31,634
  • 14
  • 90
  • 133
parnita
  • 27
  • 3
  • 3
    Please invest some time and correct the errors in your question. – Daniel Hilgarth Aug 24 '11 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). – marc_s Aug 24 '11 at 11:10
  • Lookup extension methods (which can be used on interfaces). – George Duckett Aug 24 '11 at 11:11
  • possible duplicate of [Should C# include multiple inheritance?](http://stackoverflow.com/questions/191691/should-c-include-multiple-inheritance) – Marcelo Cantos Aug 24 '11 at 11:12
  • possible duplicate of [How does using interfaces overcome the problem of multiple inheritance in C#?](http://stackoverflow.com/questions/5164582/how-does-using-interfaces-overcome-the-problem-of-multiple-inheritance-in-c) – Jakub Šturc Aug 24 '11 at 11:13

2 Answers2

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.

Ronald Wildenberg
  • 31,634
  • 14
  • 90
  • 133
  • 1
    +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. – George Duckett Aug 24 '11 at 11:14
  • Multiple inheritance means - inheriting properties and logic of two or more base class by derive class object. – parnita Aug 24 '11 at 11:57
0

c# doesn't support multiple inheritance .

Multiple Inheritance in C#

See the above link you will have clear understanding .

Community
  • 1
  • 1
62071072SP
  • 1,963
  • 2
  • 19
  • 38