multi inh
-
hi how can i multi inherit with interface please sample
-
hi how can i multi inherit with interface please sample
interface A { }
public class B { }
interface C : B, A
{}
You can only inherit one class, but you can inherit multiple interfaces. Just always put the class before the interfaces when inheriting it.
-
hi how can i multi inherit with interface please sample
-
Multiple inheritance is bad, mmkay? We prefer composition[^] :)
Bastard Programmer from Hell :suss:
Multiple implementation (of interfaces) is fine, though. A class often actually is (the test for whether inheritance is appropriate) several things defined by simple (one aspect, ideally) interfaces, and implementing each of them makes sense. For example some sort of data model class could easily be an INotifyPropertyChanged, an IEnumerable<T>, and also some kind of IDataProvider interface within your own code. Or just look at the declaration of the collection classes in the framework.
-
hi how can i multi inherit with interface please sample
What you are talking about isn't multiple inheritance, it's multiple implementation. Take the following interfaces
public interface IMyInterface
{
void DoSomething();
}public interface IAnotherInterface
{
void DoSomethingElse();
}Now, you have a class that needs to implement both of these. To do these, you add them to the class definition and then you provide an implementation for the interface methods. It looks like this:
There you go - you have now implemented two interfaces in the same class.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Multiple implementation (of interfaces) is fine, though. A class often actually is (the test for whether inheritance is appropriate) several things defined by simple (one aspect, ideally) interfaces, and implementing each of them makes sense. For example some sort of data model class could easily be an INotifyPropertyChanged, an IEnumerable<T>, and also some kind of IDataProvider interface within your own code. Or just look at the declaration of the collection classes in the framework.
BobJanova wrote:
Multiple implementation (of interfaces) is fine, though.
Multiple inheritance isn't even possible. Yes, you can implement multiple interfaces, but please don't use them to create an object that simply "binds" a few objects together; that's when a composition would be preferable. The question being phrased as it is, I'd guess that he's trying to combine an IEmployee and a IManager. ..thanks for the reminder though :)
Bastard Programmer from Hell :suss: