开发者

Identity Filter Linq .Where

I need to provide a null where clause that has no effect.

Currently I have:

f=>{f!=null;}

However that doesn't really look right. If I were to Select clients, I use

.Select(c开发者_如何转开发lients => clients)

With my filter I also get a warning about not all code paths returning a result.


Just return true:

foo.Where(f => true)

Your lambda expression doesn't work for three reasons:

  • You're trying to use f != null as a statement, which it isn't.
  • You don't have a return value.
  • It would reject null values.

The first two can be fixed by removing the braces:

foo.Where(f => f != null)

The last point means it's not really a no-op filter, which is what I guess you meant by "identity filter". Whether it's what you really want or not though, I can't say.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜