Interfaces in C#
An Interface is like an abstract class, but it can only contain signatures of methods, properties, or events.
Key Differences
- A class can implement multiple interfaces, but only inherit from one class.
- Everything in an interface is abstract and public by default.
Syntax
csharp interface IAnimal { void MakeSound(); }
class Pig : IAnimal { public void MakeSound() => Console.WriteLine("Oink"); }