简体   繁体   中英

PredicateBuilder is still true even after adding explicit false statement

I have the following statement.

var search = PredicateBuilder.True<SomeType>();
search.And(f => false);

// Still the "search" variable value is: {f => true}.

At first, I was trying an expression; nothing succeeded, so I tried this "false" instead. No matter what I did, it's still the same. What is happening?

PredicateBuilder methods don't mutate the expression (they couldn't, as expression trees are immutable) - you need to use the return value:

var search = PredicateBuilder.True<SomeType>();
search = search.And(f => false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM