Learn C#: Interfaces and Inheritance
Organize, secure, and simplify your code with interfaces and inheritance.
StartKey Concepts
Review core concepts you need to learn to master this subject
C# Interface
C# Interface
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.
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”.
Interfaces
Lesson 1 of 2
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory