CSharp examples for Custom Type:interface
Using Explicit Interface Members
using System;// ww w. ja va2 s . c om public interface IShape { double Area(); int Sides { get; } void Display(); } public interface IShapeDisplay { void Display(); } public class Square : IShape, IShapeDisplay { private int InSides; public int SideLength; public int Sides { get { return InSides; } } public double Area() { return ((double) (SideLength * SideLength)); } public double Circumference() { return ((double) (Sides * SideLength)); } public Square() { InSides = 4; } void IShape.Display() { Console.WriteLine("\nDisplaying Square Shape\'s information:"); Console.WriteLine("Side length: {0}", this.SideLength); Console.WriteLine("Sides: {0}", this.Sides); Console.WriteLine("Area: {0}", this.Area()); } void IShapeDisplay.Display() { Console.WriteLine("\nThis method could draw the shape..."); } } public class Explicit { public static void Main() { Square mySquare = new Square(); mySquare.SideLength = 7; IShape ish = (IShape) mySquare; IShapeDisplay ishd = (IShapeDisplay) mySquare; ish.Display(); ishd.Display(); } }