String Sex = getSex(); // return M or F
String[] members = getMembers(); // return member codes in array or null
//if members array is null, no filtering for member codes
var query = from tb in MemberTable
where tb.sex.Equals(Sex) &&
(members != null ? members.Contains(tb.membercode) : true)
select tb;
The code does not return the correct result. It returns all members no matter what members[].
Actually, the original LINQ is complicated, so if there are other possible solutions, I don't want to write the following:
if (members == null){ }
else { }
which is not a good coding style. Any suggestion to solve this problem?
source
share