Linq expression for filtering form

I have a FormCollection, and I just want to iterate over keys that don't contain string prices.

So I tried this ...

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

The problem is that return is not a filtered list returning its boolean values ​​... which needs a filtered list of strings ...

AllKeys returns the string [], so in a sense, I'm just trying to filter the string [] here ...

What I miss here ...

Thanks a lot!

+5
source share
2 answers

Here's the answer...

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

Are you sure you are using Where, not Select?

Using Wherewill return IEnumerable<string>what you expect.

Select IEnumerable<bool>, , , .

-1

All Articles