c# 的取负数_C#将数字列表转换为负数

如何在一行中将数​​字列表转换为负数?

我也想知道我在做什么是正确的,如果有人有改进它的建议。

我正在尝试生成一个给定半径的圆。我用列表来存储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]);

}

}提前致谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值