I want to check if an User Input is a specific number ( a 1 or a 9), if not I want him to reenter his input.
I am trying the following code:
int playerchoice = 0;
while ((Int32.TryParse(Console.ReadLine(), out playerchoice) == false) || (playerchoice != (1 | 9)))
{
Console.WriteLine("Input could not be accepted, please enter a valid number");
};
The issue seems to be with the second part of the check: No matter if I use (playerchoice != (1 | 9)) or (playerchoice != (1 & 9)), it always either checks against the 1 or the 9, not both.
What can I do to fix this? Am I using the wrong operator?
Edit: I know I could just check against each value individually, but as I plan on eventually having a lot of options this seems quite impractical.
question from:
https://stackoverflow.com/questions/65601075/c-sharp-inequality-operator-checking-against-multiple-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…