开发者

How to chain these constructors (C#)?

I'm just getting the concept of chaining constructors down, but I can't figure out how to chain these two particular constructors together, so I would appreciate it if somebody could help me out.

Thanks!

Constructors

// default constructor
// purpose: initialize data members to zero
// Parameters: none
// returns: none
public Line()
{
    startPoint.xCoord = 0;
    startPoint.yCoord = 0;
    endPoint.xCoord = 0;
    endPoint.yCoord = 0;
}


// pa开发者_如何学JAVArameterized constructor
// purpose: initialize data members to p1 and p2
// Parameters: Point objects p1 and p2
// returns: none
public Line(Point p1, Point p2)
{
    startPoint = p1;
    endPoint = p2;
}


public Line() : this(new Point(), new Point())
{
}


There's really no win in chaining these.


Try the following

public Line() : this(new Point(0,0), new Point(0,0))
{
}


This will work for you

// default constructor
// purpose: initialize data members to zero
// Parameters: none
// returns: none
public Line() : this (new Point(0, 0), new Point(0, 0))
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜