gpt4 book ai didi

c# - 如何链接这些构造函数(C#)?

转载 作者:太空宇宙 更新时间:2023-11-03 17:11:46 25 4
gpt4 key购买 nike

我只是了解链接构造函数的概念,但我不知道如何将这两个特定的构造函数链接在一起,所以如果有人能帮助我,我将不胜感激。

谢谢!

构造函数

// 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;
}

最佳答案

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

关于c# - 如何链接这些构造函数(C#)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com