Your problem is that
val
is another List but
Contains
expects a
string
To see if one list contains the values in another use the
List<t>.Intersect[
^] method and check against the
Count Any
property
E.g.
private void button1_Click(object sender, EventArgs e)
{
var l1 = new List<string> {"1", "2", "3", "4", "5", "6"};
var l2 = new List<string> { "4", "5"};
var l3 = new List<string> {"7", "8"};
ListCheck(l1, l2);
ListCheck(l1, l3);
}
private static bool ListCheck<T>(IEnumerable<T> l1, IEnumerable<T> l2)
{
if (l1.Intersect(l2).Any())
{
Console.WriteLine("matched");
return true;
}
else
{
Console.WriteLine("not matched");
return false;
}
}
Or change
val
to be a single
string