Creating a dictionary from another dictionary using LINQ

后端 未结 3 2086
自闭症患者
自闭症患者 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:37

    my_dictionary.Where(p => p.Any(v => v.Value.IsValid())
                 .ToDictionary(p=> p.Key,
                               p=> p.Value.Where(x => x.Value.IsValid());
    

    Get Only the Items that have a true in the Value, then only get the items that are true into the new dictonary.

    Filter then create the dictonary

提交回复
热议问题