Filtering out values from a C# Generic Dictionary

后端 未结 6 1984
难免孤独
难免孤独 2020-12-02 16:29

I have a C# dictionary, Dictionary that I need to be filtered based on a property of MyObject.

For example, I want to

6条回答
  •  情书的邮戳
    2020-12-02 17:01

    Since Dictionary implements IEnumerable>, you can just use Where:

    var matches = dictionary.Where(kvp => !kvp.Value.BooleanProperty);
    

    To recreate a new dictionary if you need it, use the ToDictionary method.

提交回复
热议问题