如何在一行中将数字列表转换为负数?
我也想知道我在做什么是正确的,如果有人有改进它的建议。
我正在尝试生成一个给定半径的圆。我用列表来存储x和y,所以不能完全确定这是否是最好的方法。另外下面的评论是我想要负数的地方。
private static void Generate_Circle(double x0, double y0, double radius)
{
double y, r2;
double x;
r2 = (radius * radius);
List xList = new List();
List yList = new List();
for (x = -radius; x <= radius; x += radius / 10)
{
y = Math.Sqrt(r2 - x * x);
xList.Add(x);
yList.Add(y);
}
List xxList = new List();
xxList.AddRange(xList);
xList.Reverse();
xxList.AddRange(xList);
List yyList = new List();
yyList.AddRange(yList); // This should be converted to negative values
yList.Reverse();
yyList.AddRange(yList);
for (int i = 0; i < xxList.Count; i++) // Loop through List with for
{
Console.WriteLine(xxList[i] + " " + yyList[i]);
}
}提前致谢