`
luliangok
  • 浏览: 778297 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多
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();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics