Linq expression to filter formcollection

前端 未结 2 381
情书的邮戳
情书的邮戳 2021-01-02 18:53

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 (         


        
相关标签:
2条回答
  • 2021-01-02 19:05

    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 讨论(0)
  • 2021-01-02 19:19

    Here is the answer...

    foreach (var key in collection.AllKeys.Where(k => !k.Contains("Pricing")).ToArray<string>()){ ... }
    
    0 讨论(0)
提交回复
热议问题