Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Interfaces

Interfaces define a contract: a group of related methods, properties, events and indexers that a class or struct must implement.

Features of interfaces:

  • Interfaces can inherit from other interfaces.
  • Interfaces can have a default method body. Implementing types can override it.
  • If you need methods not to appear in the implementing types' API, you can use explicit implementation, which looks like: IInterface.Method() => Console.WriteLine("Something");.

Declare an Interface

Use the interface keyword. By convention, interface names begin with a capital I.

Interfaces can contain methods, properties, events and indexers.

Inherit an Interface

The class or struct must implement all members of the interface it's implementing.

Interfaces Vs. Abstract Classes

Both interfaces and abstract classes define contracts that derived types must fulfill.

The use cases for both are a little bit confusing right now, so I'll skip them for now.

About

A program using C# interfaces.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages