Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. An interface represents a contract, in that a class that implements an interface must implement every aspect of that interface exactly as it is defined.

To define an interface:

interface ISampleInterface  
{
void doSomething();
}

To implement an interface in a class:

class SampleClass : ISampleInterface  
{
void ISampleInterface.doSomething()
{
// Method implementation.
}
}
Last modified: March 20, 2019

Author

Comments

Write a Reply or Comment