-5

i just want to ask if user input sentence is present in the array. like for example "Vince borrow book" then i just want to check if "Vince" "Borrow" and "Book" are present in arrays. im noob

string sentence = tbSentence.Text;
string[] words = sentence.Split(' ');
foreach (string word in words) 
{
    if(subjectarray.Any(word.Contains) && verbarray.Any(word.Contains))
    {
        MessageBox.Show("Sentence Valid");
    }
}
  • 3
    Right - a question in the tile, with a (poorly formatted) code fragment in the question body does not make a question that can be answered. What exactly is it that you are trying to do? Please add some context around your question. – Brendan Green Feb 12 '16 at 00:01

1 Answers1

0

You want to check that ALL words are in subjectarray AND verbarray (sure is "AND" and not "OR"?), so:

bool valid = words.All(w=>subjectarray.Contains(w) && verbarray.Contains(w));
tede24
  • 2,304
  • 11
  • 14