Can someone tell me whats the exact advantage of Interfaces in C#. To me
abstract classes serves the purpose and have all good things then what is
special about interfaces...can someone tell me some real example from
system, user, developer point of view....
An interface will allow you to publish a standard, um, interface, for
making use of a functionality. For instance, you may write a sorting
library, and you want it to be generally available to other classes.
You publish an interface, consisting of a set of functions, that
classes have to implement in order to be able to use your library. Or
if you want your class to be able to implement BeginInvoke and
EndInvoke, you have to implement the ISynchronizeInvoke interface.
Implementing just means you have to supply a version of the functions
defined by the interface within your class.
..NET implements a number of interfaces, all of which start with "I",
as in IComparable, ICollection, etc. Classes that implement the
interface can use the functionality.
So if you are writing a class "smee" that you want to be able to sort,
use asynchronous communications, and serialize to a file (or
something), you'd define it as
class smee : IComparable, ISynchronizeInvoke, ISerializable {}
and implement all the required methods for those interfaces, then you
can hand a smee to any method that requires one of those interfaces.