如果语句与c#中的加法内联

JTu*_*ney -3 c# c#-4.0

C#不喜欢以下内容.我怎样才能重写它以便它有效?

Value1 = Value1 + (i.Cost == null || !Utils.IsNumeric(i.Cost)) ? 0 : i.Cost;
Run Code Online (Sandbox Code Playgroud)

小智 6

试试这个

Value1 += (i.Cost == null || !Utils.IsNumeric(i.Cost)) ? 0 : i.Cost;
Run Code Online (Sandbox Code Playgroud)


Dan*_*rly 5

你有一个不匹配的括号.代码应如下所示:

Value1 = Value1 + (i.Cost == null || !Utils.IsNumeric(i.Cost) ? 0 : i.Cost);
Run Code Online (Sandbox Code Playgroud)

或者可能

Value1 = Value1 + ((i.Cost == null || !Utils.IsNumeric(i.Cost)) ? 0 : i.Cost);
Run Code Online (Sandbox Code Playgroud)

我个人会重构这段代码以提高可读性,但这是另一天的一个论点.