Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用较短的代码使++运算符递增堆栈?_C#_Increment - Fatal编程技术网

C# 如何使用较短的代码使++运算符递增堆栈?

C# 如何使用较短的代码使++运算符递增堆栈?,c#,increment,C#,Increment,我想找出一种方法,使我的浮点移动和更改速度比典型的x++更快,所以我决定在同一while循环中添加更多的增量,以便它们堆叠起来 While (True) { x++; x++; x++; x++; } 功能正常,但如何使用较短的代码实现此功能?您可以将其替换为: x += 4; // Adds 4 to x, and stores the result in x. while (...) { x += 4; } 这表示x=x+4 您还可以分别使用减法

我想找出一种方法,使我的浮点移动和更改速度比典型的x++更快,所以我决定在同一while循环中添加更多的增量,以便它们堆叠起来

While (True)
{
    x++;
    x++;
    x++;
    x++;
}

功能正常,但如何使用较短的代码实现此功能?

您可以将其替换为:

x += 4; // Adds 4 to x, and stores the result in x.
while (...)
{
    x += 4;
}
这表示x=x+4

您还可以分别使用减法、乘法和除法-=、*=、和/=。阅读更多信息

Try+=操作员:

x+=4;

这样x将增加4。

使我的浮点移动并改变吗?这些x++的用途是什么?你能展示一些比whiletrue更真实的代码吗?与@Alexei:x=double.PositiveInfinity;-更快,而且不需要循环@MarcGravel——我认为结果实际上会小得多。在某一点上,x+1和x不一样吗?@Alexei的确,刻度和精度最终会下降1秒。我的观点主要是回应你的观察,即没有更多的上下文,这个问题就没有意义。见鬼,尽管如此;也会起到同样的作用。