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.
精彩评论