is there anyway of fixing this statement
if (sAwnser == ("hello" || "Hello" || "hi" || "Hi" || "hey" || "Hey" || "Hay" || "hey"))
{
}
it comes up with the error
Operator '||' cannot be applied to operands of type 'string' and 'string'
if anyone can help it would be much appreciated
For avoiding so many comparisons you can do
var list = new string[] {"hello", "Hello", "hi", "Hi", "hey", "Hey", "Hay", "hey"};
if (list.Contains(answer))
{
}
You have to explicitly reference the first variable every time.
sAwnser == "hello"
returns a boolean. You cannot compare a boolean to a string.
What you could do is create a collection and add all your separate strings to that. Afterwards you can use .Contains()
on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With