An expression in Linq that always returns true

.net c# expression-trees linq

Question

I need to pass a parameter to a method that requires an Expression<Func<T, bool>>.

How to do I pass an expression that would always return true?

Using obj => true doesn't work because the framework complains at runtime that it cannot determine the memeber type from the True constant.

1
5
3/31/2011 12:31:13 PM

Popular Answer

If you have a function like this

void TakeExpression<T>(Expression<Func<T, bool>> expr)

You should call it this way, specifying the T type :

TakeExpression<int>(_ => true)

It should work.

11
3/31/2011 12:40:37 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow