开发者

Linq expression to filter formcollection

I have a FormCollection and I just want to only iterate through the keys the do not contain the string pricing.

So what I tried was this...

foreach (var key in collection.AllKeys.Where(k => !k.Contains("Pricing"))){ ... }

The problem is the return is not a filtered list its returning boolean values... in which in need the filtered list of 开发者_开发技巧string...

AllKeys returns a string[] so in a sense I am just trying to filter a string[] here...

What I am missing here...

Thanks much!


Here is the answer...

foreach (var key in collection.AllKeys.Where(k => !k.Contains("Pricing")).ToArray<string>()){ ... }


Are you sure that you're using Where and not Select?

Using Where will return an IEnumerable<string> which is what you're expecting.

Using Select will return an IEnumerable<bool> which is what you say is actually happening.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜