Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0163 interface

An interface defines a series of members the implementer must implement. An interface itself doesn't provide any implementation. A class can implement any number of interfaces. A struct can implement interface as well. An interface can only have methods, properties, events and indexers. The following code defines an interface. using System; interface Printable{ void Print(); } class Rectangle : Printable{ int Width; public void Print(){ Console.WriteLine("Width:"+Width); } } class Test { static void Main() { Printable r = new Rectangle(); r.Print(); } } The output: Width:0