Start out writing the method that can perform the And operation that you want on just two values, using the logic that you described. This is actually handled quite easily, as if either value is False
you return False
, if none is False
and one is NA
you return NA
, and if both are true you return true, the only remaining case.
public static myEnum And(this myEnum first, myEnum second)
{
if (first == myEnum.False || second == myEnum.False)
return myEnum.False;
if (first == myEnum.NA || second == myEnum.NA)
return myEnum.NA;
return myEnum.True;
}
Next, it appears that you want to compare the item from each list that is at the same index, so the first is compared to the first, the second to the second, etc., to create a new list of the same size as the other two. You can use Zip
, to perform this logical operation using the method we've already defined:
var query = list1.Zip(list2, (a,b) => a.And(b));