OR 运算符的问题
Problems with OR operator
我正在使用一个 foreach 循环,它根据列表中的项目数量重复自身。每次重复时,它都会检查两个文本框的值是否为“0”。如果他们(或其中之一)这样做,那么我检查它正在迭代的小时的汇总值是否是(或不是。在 "end" 评论之后的部分的情况下)某个值。如果不是,那么我使用 OR 运算符 (||) 对下一个执行相同的操作。但是,这不起作用。
我正在使用 debug.writeline 查看循环在哪里找到匹配项。无论出于何种原因,它始终为 0 - 即使迭代 0 的 hour.summary 的值为 "Rain",这应该使 if 无法找到匹配项并触发 else。
foreach (var hour in result.Hourly.Hours)
{
//Start
if (starttemp.Text == "0")
{
if ((hour.Summary == "Rain") || (hour.Summary == "Snow") || (hour.Summary == "Drizzle") || (hour.Summary == "Light Rain") || (hour.Summary == "Light Snow") || (hour.Summary == "Heavy Rain") || (hour.Summary == "Heavy Snow"))
{ starttemp.Text = hour.Temperature.ToString(); Debug.WriteLine("SET START WITH " + hour.Summary + " AT HOUR " + increment); }
else
{ }
}
//End
if (endtemp.Text == "0")
{
if ((hour.Summary != "Rain") || (hour.Summary != "Snow") || (hour.Summary != "Drizzle") || (hour.Summary != "Light Rain") || (hour.Summary != "Light Snow") || (hour.Summary != "Heavy Rain") || (hour.Summary != "Heavy Snow"))
{ endtemp.Text = hour.Temperature.ToString(); Debug.WriteLine("SET END WITH " + hour.Summary + " AT HOUR " + increment); }
else
{ }
}
increment = increment + 1;
}
行
if ((hour.Summary != "Rain") || (hour.Summary != "Snow") || (hour.Summary != "Drizzle") || (hour.Summary != "Light Rain") || (hour.Summary != "Light Snow") || (hour.Summary != "Heavy Rain") || (hour.Summary != "Heavy Snow"))
永远是真的...
我不是 100% 确定您要做什么,但我认为您应该更换 ||与&&
我正在使用一个 foreach 循环,它根据列表中的项目数量重复自身。每次重复时,它都会检查两个文本框的值是否为“0”。如果他们(或其中之一)这样做,那么我检查它正在迭代的小时的汇总值是否是(或不是。在 "end" 评论之后的部分的情况下)某个值。如果不是,那么我使用 OR 运算符 (||) 对下一个执行相同的操作。但是,这不起作用。
我正在使用 debug.writeline 查看循环在哪里找到匹配项。无论出于何种原因,它始终为 0 - 即使迭代 0 的 hour.summary 的值为 "Rain",这应该使 if 无法找到匹配项并触发 else。
foreach (var hour in result.Hourly.Hours)
{
//Start
if (starttemp.Text == "0")
{
if ((hour.Summary == "Rain") || (hour.Summary == "Snow") || (hour.Summary == "Drizzle") || (hour.Summary == "Light Rain") || (hour.Summary == "Light Snow") || (hour.Summary == "Heavy Rain") || (hour.Summary == "Heavy Snow"))
{ starttemp.Text = hour.Temperature.ToString(); Debug.WriteLine("SET START WITH " + hour.Summary + " AT HOUR " + increment); }
else
{ }
}
//End
if (endtemp.Text == "0")
{
if ((hour.Summary != "Rain") || (hour.Summary != "Snow") || (hour.Summary != "Drizzle") || (hour.Summary != "Light Rain") || (hour.Summary != "Light Snow") || (hour.Summary != "Heavy Rain") || (hour.Summary != "Heavy Snow"))
{ endtemp.Text = hour.Temperature.ToString(); Debug.WriteLine("SET END WITH " + hour.Summary + " AT HOUR " + increment); }
else
{ }
}
increment = increment + 1;
}
行
if ((hour.Summary != "Rain") || (hour.Summary != "Snow") || (hour.Summary != "Drizzle") || (hour.Summary != "Light Rain") || (hour.Summary != "Light Snow") || (hour.Summary != "Heavy Rain") || (hour.Summary != "Heavy Snow"))
永远是真的...
我不是 100% 确定您要做什么,但我认为您应该更换 ||与&&