Filtering out values from a C# Generic Dictionary

后端 未结 6 1964
难免孤独
难免孤独 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 16:54

        public static Dictionary Where(this Dictionary instance, Func, bool> predicate)
        {
            return Enumerable.Where(instance, predicate)
                             .ToDictionary(item => item.Key, item => item.Value);
        }
    

提交回复
热议问题