【发布时间】:2014-08-02 09:15:26
【问题描述】:
所以我有这个代码部分:
private int checkErrors() {
int error = 0;
if (!(nether.Text.Equals("true"))) { error += 1; }
if (!(nether.Text.Equals("false"))) { error += 1; }
if (!(fly.Text.Equals("true"))) { error += 1; }
if (!(fly.Text.Equals("false"))) { error += 1; }
if (!(achivments.Text.Equals("true"))) { error += 1; }
if (!(achivments.Text.Equals("false"))) { error += 1; }
if (!(whitelist.Text.Equals("true"))) { error += 1; }
if (!(whitelist.Text.Equals("false"))) { error += 1; }
if (!(pvp.Text.Equals("true"))) { error += 1; }
if (!(pvp.Text.Equals("false"))) { error += 1; }
if (!(commandBlock.Text.Equals("true"))) { error += 1; }
if (!(commandBlock.Text.Equals("false"))) { error += 1; }
if (!(spawnMonster.Text.Equals("true"))) { error += 1; }
if (!(spawnMonster.Text.Equals("false")) { error += 1; }
return error;
}
但无论如何它会让我知道'error = 7',因为当一个陈述为真时,另一个陈述为假
所以我的问题是:
有没有办法将两个字符串与第三个字符串进行比较?
其他示例:我有字符串userInput,如果userInput 不等于"a" 或"b" 则执行error += 1;!
【问题讨论】:
-
我在猜测.. 你的意思是
Text可以是true或者是false如果不是error += 1? -
“有没有办法将 2 个字符串与第三个字符串进行比较?”这一行是什么意思。
-
我有 2 个固定字符串,想将它们与变量第三个字符串进行比较
标签: c# if-statement compare