C# &引用<;=是一个无效的表达术语;及“预期”;

C# &引用<;=是一个无效的表达术语;及“预期”;,c#,C#,我正在摆弄C#,正在制作一个原型GUI(没有附加游戏,只是摆弄按钮和按钮颜色)。我遇到了一个错误: private void temperValue_Load(object sender, EventArgs e) { int temperInt = 23; temperInt = Convert.ToInt32(temperValue.Text); if (temperInt >= 70) {

我正在摆弄C#,正在制作一个原型GUI(没有附加游戏,只是摆弄按钮和按钮颜色)。我遇到了一个错误:

private void temperValue_Load(object sender, EventArgs e)
    {
        int temperInt = 23;
        temperInt = Convert.ToInt32(temperValue.Text);

        if (temperInt >= 70)
        {
            temperButton.BackColor = System.Drawing.Color.Red;
        }
        else if (temperInt >= 40 & <= 69)
        {
            temperButton.BackColor = System.Drawing.Color.DarkOrange;
        }
    }
private void temperValue\u加载(对象发送方,事件参数e)
{
int-temperInt=23;
temperInt=Convert.ToInt32(temperValue.Text);
如果(温度积分>=70)
{
temperButton.BackColor=System.Drawing.Color.Red;
}

否则,如果(temperInt>=40&您不能在这样的布尔条件下使用快捷方式

else if (temperInt >= 40 & <= 69)

else如果(temperInt>=40&=40&&temperInt您不能在这样的布尔条件下使用快捷方式

else if (temperInt >= 40 & <= 69)

else if(temperInt>=40&=40&&temperInt您可能是指
temperInt>=40&&temperInt您可能是指
temperInt>=40&&temperInt
else if(temperInt>=40&=40&&temperInt给定代码中有一些错误

 else if (temperInt >= 40 & <= 69)
    {
        temperButton.BackColor = System.Drawing.Color.DarkOrange;
    }

else如果(temperInt>=40&=40&&temperInt给定代码中有一些错误

 else if (temperInt >= 40 & <= 69)
    {
        temperButton.BackColor = System.Drawing.Color.DarkOrange;
    }
else如果(temperInt>=40&=40&&temperInt
这更接近于自然语言,但对于这种情况来说,这可能是矫枉过正了


它更接近自然语言,但对于这种情况,这可能有点过头了。

我可以问一下:这两者之间有什么区别吗?(我的意思是额外的“AND”是做什么的。我知道它在那里)&&是逻辑的“AND”是按位的,两个“AND”用于比较布尔值。一个“AND”用于按位操作。(对于
|
操作符也是如此)@h3half:这个答案的最后一段是不正确的。
&
不能用于布尔人。这是完全合法的;试试看!不同的是
总是计算两个部分。
|
跳过计算右半部分,如果左半部分为真。
&也一样e> --如果左半部分为假,则不计算右半部分。但如果说运算符不适用于布尔值,则完全是错误的;它们当然适用。@KeithNicholas和Kirk Wolf:我鼓励您阅读C#4规范的第7.11.3节。请问:两者之间有什么区别?(我的意思是额外的“与”是做什么的。我知道它就在那里)&&是逻辑“与”是一个按位的,两个“与”用于比较布尔值。一个“与”用于按位操作。(对于
|
操作符也是如此)@h3half:这个答案的最后一段是不正确的。
&
不能用于布尔人。这是完全合法的;试试看!不同的是
总是计算两个部分。
|
跳过计算右半部分,如果左半部分为真。
&也一样e> --如果左半部分为假,则不计算右半部分。但如果说运算符不适用于bools,则完全是假;它们当然适用。@KeithNicholas和Kirk Wolf:我鼓励您阅读C#4规范的第7.11.3节。除了正确答案之外,是否还检查
:阅读时也更清楚呃,如果你这样写代码:
if(40)除了检查正确答案之外,没有检查
:如果你这样写代码,读者也会更清楚:
if(40
 else if (temperInt >= 40 & <= 69)
    {
        temperButton.BackColor = System.Drawing.Color.DarkOrange;
    }
 else if (temperInt >= 40 && temperInt <= 69)
    {
        temperButton.BackColor = System.Drawing.Color.DarkOrange;
    }
if (temperInt >= 40 & <= 69) ...
if (temperInt >= 40 && temperInt <= 69) ...
bool IsBetween (this int me, int lower, int upper) { 
    return (me >= lower) && (me <= upper); 
}

if (temperInt.IsBetween (40, 69)) ...