gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:54:15 35 4
gpt4 key购买 nike

有没有办法修正这个语句

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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com