如何链接这些构造函数(C#)?
我刚刚了解了链接构造函数的概念,但我不知道如何将这两个特定的构造函数链接在一起,所以如果有人可以帮助我,我将不胜感激。
谢谢!
构造函数
// 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;
}
// parameterized 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;
}
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;
}
// parameterized 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将这些链接起来确实没有任何好处。
There's really no win in chaining these.
尝试以下操作
Try the following
这对你有用
This will work for you