gpt4 book ai didi

c# - =+ 是什么意思,为什么要编译?

转载 作者:太空狗 更新时间:2023-10-29 22:32:25 25 4
gpt4 key购买 nike

我有以下错字:

subcomponentGroupCount = +subcomponentCount;

用于以下方面:

int subcomponentGroupCount = 0;

foreach (Subcomponent subcomponent in group.Subcomponents)
{
int subcomponentCount = task.TaskDevice.TaskDeviceSubcomponents.Count(tds => tds.TemplateID == subcomponent.TemplateID);
subcomponentGroupCount = +subcomponentCount;
}

我打算将它设为 +=,但我想知道“= +var”是什么意思......

最佳答案

+ 运算符可以用作二元一元运算符。来自 MSDN :

Unary + operators are predefined for all numeric types. The result of a unary + operation on a numeric type is just the value of the operand.

您可以为自定义类型重载此运算符,但对于内置数字类型,这本质上是空操作。

关于c# - =+ 是什么意思,为什么要编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21742500/

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