日期:2014-05-17 浏览次数:20946 次
public enum PointColor
{LightBlue,BloodRed,Gold}
class Point
{
public int X{get;set;}
public int Y{get;set;}
public PointColor Color{get;set;}
public Point(int Xval,int Yval)
{
X = Xval;
Y = Yval;
Color = PointColor.Gold;
}
public Point(PointColor ptColor)
{
Color = ptColor;
}
public Point()
{
:this(PointColor.BloodRed){}
}
public void DisplayStats()
{
Console.WriteLine("[{0},{1}]",X,Y);
Console.WriteLine("Point is {0}",Color);
}
}
//使用初始化语法调用自定义构造函数
Point goldPoint = new Point(PointColor.Gold){X = 90,Y = 20};
Console.WriteLine("Value of Point is : {0}",goldPoint.DisplayStats());
//第一种
Point goldPoint = new Point(90,20){Color = PointColor.Gold};
//第二种
Point goldPoint = new Point{X = 90,Y = 20,Color = PointColor.Gold};