I am trying to write a Function using an If statement that checks an array of Defenition for a word and if one of them is right, it operates a “Success” Void, else it “Fails”.
Question is, how to I properly combine the If and For statesments?
(It also needs to check it’s property is not Null…)
It all works fine with stupid “Linear” coding:
private void Check()
{
if ((textBox2.Text == Heb[Line].Def[0] || textBox2.Text == Heb[Line].Def[1] || textBox2.Text == Heb[Line].Def[2] || textBox2.Text == Heb[Line].Def[3] || textBox2.Text == Heb[Line].Def[4])&& textBox2.Text != "")
{
Success();
}
else
{
Fail();
}
}
But i am sure there is a better and finer way to phrase it.
I want to use the “foreach” method to check def[].
I guess it should look something like:
if (foreach(int i in Heb[line].Def{(if Heb[Line].Def[i]==textBox2.Text})) something something...
1 Answer