有没有办法修正这个语句
if (sAwnser == ("hello" || "Hello" || "hi" || "Hi" || "hey" || "Hey" || "Hay" || "hey"))
{
}
出现错误
Operator '||' cannot be applied to operands of type 'string' and 'string'
如果有人能提供帮助,我们将不胜感激
最佳答案
为了避免这么多你可以做的比较
var list = new string[] {"hello", "Hello", "hi", "Hi", "hey", "Hey", "Hay", "hey"};
if (list.Contains(answer))
{
}
关于c# - 在 "or"语句中对字符串使用 "if"运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19742259/