Interface Example

CSharp · Console

/Program.cs

using System;

public class Program
{
  public interface IShape {
    void Draw();
    double Area();
  }

  class Circle : IShape {
    public double Radius { get; set; }

    public Circle(double radius) {
      Radius = radius;
    }

    public void Draw() {
      // draw a circle!
    }
    public double Area() {
      return Math.PI * Math.Pow(Radius, 2);
    }
  }

  public static void Main() {
    IShape c = new Circle(5);
    Console.WriteLine(c.Area());
    // 78.5398163397448
  }
}
;