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?".
selectedValue is a string then list2.Contains(selectedValue). Take a look at the Enumerable class and all the extension methods it provides.ss from the list contained inside str?Any with FirstOrDefault, the return value is going to be the first s that is contained in str or null if no such string exists in the list.You could use this:
if (myList.Any(x => mystring.Contains(x)))
// ....