Returning the existence of a key in a dict by searching key substring

前端 未结 6 771
借酒劲吻你
借酒劲吻你 2020-12-20 09:08

I have a dictionary of string people (key) and string addresses (value). I want to have an if statement that returns true if any key in my dictionary contains the substring

6条回答
  •  抹茶落季
    2020-12-20 09:59

    You'll have to iterate over the collection and check each one. The LINQ Any method makes this fairly simple:

    dict.Keys.Any(k => k.Contains("anders"))
    

提交回复
热议问题