C# Interface

Last modified: July 11, 2021

Another way to achieve abstraction in C# is with interfaces. It is best to start an interface name with the I letter

interface IVehicle { public void Start(); public void Brake(); public void Stop(); } class Car : IVehicle { public void Brake() { Console.WriteLine("Brake the car"); } public void Start() { Console.WriteLine("Start the car"); } public void Stop() { Console.WriteLine("Stop the car"); } } class Program { static void Main(string[] args) { Car myCar = new Car(); // Create a Car object myCar.Start(); myCar.Brake(); myCar.Stop(); } }