嗨,我的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])
{
}
感谢您的帮助!!!!
答案 0 :(得分:1)
userAnswer = questionResponseArray[0]
不正确。
=
是赋值运算符,而==
是相等运算符