C# 不等式运算符:检查多个值

C# Inequality Operator: Checking against multiple values

我想检查用户输入是否是特定数字(1 或 9),如果不是,我希望他重新输入。 我正在尝试以下代码:

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");
            };

问题似乎出在检查的第二部分:无论我使用 (playerchoice != (1 | 9)) 还是 (playerchoice != (1 & 9)),它总是检查1 或 9,而不是两者。

我该怎么做才能解决这个问题?我用错运算符了吗?

编辑:我知道我可以单独检查每个值,但由于我计划最终有很多选项,这似乎很不切实际。

最简单的方法是分别检查每个值,但如果要检查的数字很多,另一种方法是使用 HashSet。这是一个简单的例子:

class Program {
    private static readonly HashSet<int> nums = new HashSet<int> { 1, 9, ... };
    public static void Main(string[] args) {
        int i = int.Parse(Console.ReadLine());
        if (nums.Contains(i)) {
            // do something
        } else {
            // do something else
        }
    }
}