LINQ Search into a List a joined string : If we have a string whose values are joined with a character (for example a comma) we can use the condition Any to determine if some element of the sequence satisfies a condition and use the Contains in the condition to find the string.

// joined string
string values = "value1,value2"; // sequence
List<string> searchList = new List<string>() { "value1", "value3" }; // search into the sequence
bool found = values.Split(',').Any(x => searchList.Contains(x));
Tagged:

Laisser un commentaire