I have an if statement, where I would like to check, if a string contains any item of a list<string>
.
if (str.Contains(list2.Any()) && str.Contains(ddl_language.SelectedValue))
{
lstpdfList.Items.Add(str);
}
The correct formulation is
list2.Any(s => str.Contains(s))
This is read as "does list2
include any string s
such that str
contains s
?".
You could use this:
if (myList.Any(x => mystring.Contains(x)))
// ....