Ok, if you have inheritance sorted, then Interfaces aren't too difficult.
I assume you know about
foreach
in C#? And that you can give it any form of Collection (List<T>, array, and so forth)?
This works because all Collections implement an Interface called IEnumerable - indeed, you can declare your own class, implement the IEnumerable interface and it will work happily in a
foreach
.
This happens because when you implement an interface, you provide a set of routines that define it: The equivalent of FindFirst and FindNext for IEnumerable. So when foreach needs to find the first element in the list, it calls the IEnumerable FindFirst method (which you implemented in your class) and your version gets called. The same for FindNext each time it goes round the loop again.
What interfaces do is allow a class to implement a number of behaviors and act as if the class was derived from the interface (sort of). Since C# will only let you derive from a single class, (but an unlimited number of interfaces) it allows behaviour that seems like multiple inheritance.
The difference between an Interface and a class is also pretty simple: when you declare an interface, you are not allowed to declare any code - just the bare-bones of the properties and methods. The actual code must be filled in by the class that implements the interface.
To declare an interface is simple: I won't demo it, because MSDN does a much better job.
http://msdn.microsoft.com/en-us/library/87d83y5b(v=vs.80).aspx[
^]
They are a bit difficult to get your head round, but they are important, and you have probably already used them a lot more than you think! :laugh: