c# - 在 "or"语句中对字符串使用 "if"运算符

标签 c# string

有没有办法修正这个语句

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/

相关文章:

c# - Raspberry Pi+MonoDevelop如何从串口读取数据?

javascript - 从 JavaScript 中的字符串中提取随机数

C内存重叠?

复制 char 指针数组

javascript - 代替 。用~

c# - ListBox ItemsSource 不更新

c# - Entity Framework 不加载相关对象

c# - 将一个长字符串拆分为一组较短的字符串

c# - 用二分查找查找数字——最大和最小操作数

mysql - 如何将两个单独的文本连接到一个 - 从字符串中选择 - IN MySQL