C# Interface

Interfaces

Another way to achieve abstraction in C#, is with interfaces.

An interface is a completely “abstract class“, which can only contain abstract methods and properties (with empty bodies):

Example

// interface
interface Animal 
{
  void animalSound(); // interface method (does not have a body)
  void run(); // interface method (does not have a body)
}

It is considered good practice to start with the letter “I” at the beginning of an interface, as it makes it easier for yourself and others to remember that it is an interface and not a class.

By default, members of an interface are abstract and public.

Note: Interfaces can contain properties and methods, but not fields.

Continue reading C# Interface