我有个问题。我该如何解决?谢谢 [英] I have a problem. How can I fix it? Thanks
问题描述
if((Math.Pow(stranac,2))=(Math.Pow(stranaa,2)+(Math.Pow(stranab,2))))
我有错误
作业的左侧必须是变量,属性或索引器
我尝试过:
我无法修复它。我不明白这个错误。
if ((Math.Pow(stranac, 2)) = (Math.Pow(stranaa, 2) + (Math.Pow(stranab, 2))))
and I have Error
The left-hand side of an assignment must be a variable, property or indexer
What I have tried:
I can´t fix it. I don´t understand this error.
推荐答案
这是因为你使用赋值运算符(=
)代替等式比较运算符(==
)。
此外,对于2的幂,使用简单乘法而不是Math.Pow
方法。
建议的解决方案:
It is because you use the assignment operator (=
) instead of the equality comparison operator (==
).
Moreover, for a power of two it is more efficient to use a simple multiplication instead of theMath.Pow
method.
Proposed solution:
if ((stranac * stranac) == (stranaa * stranaa + stranab * stranab))
希望这会有所帮助。好的。
Hope this helps. Kindly.
这意味着作业的左侧必须是变量,如
It means that the left side of an assignment must be a variable as in
double c = Math.Pow(stranaa, 2) + Math.Pow(stranab, 2);
您可能想要进行比较( ==
):
You probably wanted to perform a comparison (==
):
if ((Math.Pow(stranac, 2)) == (Math.Pow(stranaa, 2) + (Math.Pow(stranab, 2))))
但请注意,由于浮点值和操作的精确度,这种相等的比较不应与浮点值一起使用。请参阅浮点指南 - 比较 [ ^ ]。
But note that such comparisons for equality should not be used with floating point values due to the inprecision of floating point values and operations. See The Floating-Point Guide - Comparison[^].
这篇关于我有个问题。我该如何解决?谢谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!