3

所以我得到了这个代码:

ClassA { List<ClassB> classBList;}
ClassB { List<ClassC> classCList;}
ClassC { String ID;}

Dictionary<string,int> dict;
ClassA MyObject;

字典上的键应该与 ClassC 上的 ID 字段匹配我想在 linq 上执行以下查询

List<String> matches = (from b in MyObject
                      from c in b.classCList
                      join d in dict
                      on c.ID equals dict.Key
                      select new
                      {
                          c.Value == 0 ? "YES" : "NO"
                      }).ToList();

但我得到了错误:"Invalid anonymous type member ..."

底线是......我怎么能在选择新的条件下?

编辑

如何使用扩展方法进行此查询?

有什么帮助吗?泰

4

1 回答 1

10

您尝试选择匿名类型,然后尝试将结果分配回List<string>. 您的查询应该是:

List<String> matches = (from b in MyObject.classBList
                        from c in b.classCList
                        join d in dict
                        on c.ID equals d.Key
                        select d.Value == 0 ? "YES" : "NO").ToList();
于 2013-10-04T17:19:04.163 回答