在if语句中使用字符串会引发错误“运算符'||'不能应用于操作数字符串和字符串“

时间:2020-02-26 09:46:14

标签: c#

嗨,我的c#不再是以前的样子,只是在使用Java脚本一段时间后才回来。 本质上,我只是在尝试使用数组索引做一个简单的if语句,但是我收到了错误消息。

"Operator '||' cannot be applied to operands string and string" 

这是怎么回事,因为它实际上变成了布尔。


            string[] userCustomAnswerArray = {"It needs to be reaplaced", "This could be improved", "I struggle to see this"};
            int customResponseindex = rand.Next(0, 3);

            string[] questionResponseArray = { "Yes", "No but not a problem", userCustomAnswerArray[customResponseindex]  };
            int questionResponseIndex = rand.Next(0, 3);
            string userAnswer = questionResponseArray[questionResponseIndex];

                    if (userAnswer = questionResponseArray[0] || userAnswer = questionResponseArray[1])
                    {

                    }

感谢您的帮助!!!!

1 个答案:

答案 0 :(得分:1)

userAnswer = questionResponseArray[0]不正确。

=是赋值运算符,而==是相等运算符

相关问题