Home > OS >  Lambda expression compare boolean as false or true
Lambda expression compare boolean as false or true

Time:08-05

Is there a way to simplify the following code (Lambda expression compare boolean as false)

allUsers.Where(g => g.IsAMember == false).ToList();
allUsers.Where(g => g.IsAMember == true).ToList();

CodePudding user response:

If IsAMember is a boolean (non-nullable one) then you should be able to simply do:

var nonMembers = allUsers
    .Where(g => !g.IsAMember)
    .ToList();

And

var members = allUsers
    .Where(g => g.IsAMember)
    .ToList();
  • Related