so i have this code part:
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;
}
but in any way it will get me that 'error = 7'
because when one statement is true the other is false
so my question is:
Is there a way to compare 2 strings to a third string ?
other example: i have the string userInput
and i want, if userInput
not equals "a"
or "b"
to execute error += 1;
!
I suspect you're trying to find cases where it isn't "true" and it isn't "false". So something like:
if (spawnMonster.Text != "true" && spawnMonster.Text != "false")
{
error++;
}
Alternatively, express the condition once, and apply it to all your strings:
var strings = new[] { nether.Text, fly.Text, achivments.Text, whitelist.Text
pvp.Text, commandBlock.Text, spawnMonster.Text };
return strings.Count(t => t != "true" && t != "false");
See more on this question at Stackoverflow