Codecademy Logo

Learn C#: Interfaces

Related learning

  • Learn intermediate C# concepts like inheritance, asynchronous programming, events, iterators, and more to build efficient applications.
    • With Certificate
    • Intermediate.
      30 hours
  • Jumpstart your career with this skill path, first by learning the C# language, then building web apps with ASP.NET Core and the Razor Pages.
    • Includes 7 Courses
    • With Certificate
    • Intermediate.
      41 hours

C# Interface

In C#, an interface contains definitions for a group of related functionalities that a class can implement.

Interfaces are useful because they guarantee how a class behaves. This, along with the fact that a class can implement multiple interfaces, helps organize and modularize components of software.

It is best practice to start the name of an interface with “I”.

interface IAutomobile
{
string LicensePlate { get; }
double Speed { get; }
int Wheels { get; }
}
// The IAutomobile interface has three properties. Any class that implements this interface must have these three properties.
public interface IAccount
{
void PayInFunds ( decimal amount );
bool WithdrawFunds ( decimal amount );
decimal GetBalance ();
}
// The IAccount interface has three methods to implement.
public class CustomerAccount : IAccount
{ }
// This CustomerAccount class is labeled with : IAccount, which means that it will implement that interface.

Learn more on Codecademy

  • Learn intermediate C# concepts like inheritance, asynchronous programming, events, iterators, and more to build efficient applications.
    • With Certificate
    • Intermediate.
      30 hours
  • Jumpstart your career with this skill path, first by learning the C# language, then building web apps with ASP.NET Core and the Razor Pages.
    • Includes 7 Courses
    • With Certificate
    • Intermediate.
      41 hours