c#利用接口实现多重继承

1104人阅读 评论(0) 收藏 举报
using System;
 
public interface IShape
{
   // Cut out other methods to simplify example.
   double Area();
   int Sides { get; }
}
 
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;
  }
 
   public void Display()
   {
      Console.WriteLine("/nDisplaying Square information:");
      Console.WriteLine("Side length: {0}", this.SideLength);
      Console.WriteLine("Sides: {0}", this.Sides);
      Console.WriteLine("Area: {0}", this.Area());
   }
}
 
public class Multi
{
   public static void Main()
   {
      Square mySquare = new Square();
      mySquare.SideLength = 7;
 
      mySquare.Display();
   }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:915647次
    • 积分:10463
    • 等级:
    • 排名:第1580名
    • 原创:189篇
    • 转载:61篇
    • 译文:0篇
    • 评论:202条
    博客专栏