Creating a dictionary from another dictionary using LINQ

后端 未结 3 2116
自闭症患者
自闭症患者 2020-12-29 04:59

I have a dictionary of the type:

IDictionary> my_dictionary

bar class looks like this:

cl         


        
3条回答
  •  抹茶落季
    2020-12-29 05:45

    var new_dict = my_dictionary.Select(x => new KeyValuePair>(
                                                     x.Key,
                                                     x.Value
                                                      .Where(y => y.IsValid)
                                                      .ToList()))
                                .Where(x => x.Value.Count > 0)
                                .ToDictionary(x => x.Key, x => x.Value.AsReadOnly());
    

提交回复
热议问题