Interfaces
An interface lists members a class must implement. A class can implement many interfaces.
Example
foreach (IShape s in new IShape[] { new Sq(2), new Circle(1) }) Console.WriteLine(s.Area());
interface IShape { double Area(); }
class Sq(double s) : IShape { public double Area() => s * s; }
class Circle(double r) : IShape { public double Area() => Math.Round(Math.PI * r * r, 2); }Exercise
Implement an interface.
class A : {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.