I have this code:
if (textBox1.Text == "one" || "two")
I have tried to use || and | to add more strings, but it says that it cannot be applied to operands of type "bool" and "string". How can I make this work? Thank you.
I have this code:
if (textBox1.Text == "one" || "two")
I have tried to use || and | to add more strings, but it says that it cannot be applied to operands of type "bool" and "string". How can I make this work? Thank you.
Try this
if (textBox1.Text == "one" || textBox1.Text == "two")
or alternatively :
var strings = new List<string>() {"one", "two", "thee", .... "n"};
if(strings.Contains(textBox1.Text)){
}
You can't combine operators in the way I suspect you are trying:
if (textBox1.Text == "one" || "two")
You need to qualify each condition as follows:
if (textBox1.Text == "one" || textBox1.Text == "two")
There are ways to make this easier to do, see answers to this question for an alternative way to do it
I'd recommend to use:
var options = new [] { "one", "two" };
if (options.Contain(textBox1.Text))
...