没有超载的方法'选择'需要2个参数

时间:2014-08-24 21:56:12

标签: c# linq lambda

我正在尝试从我的查询中获取两个值,但我收到此错误:

“方法'选择'没有重载需要2个参数”

这是我的代码:

    public class myType
    {
        public long anId{ get; set; }
        public float aCost{ get; set; }
    }

    IEnumerable<myType> result = myDataTable.AsEnumerable().GroupBy(p => p["Id"]).Select(a => a["Id"], t => t.Sum(p => p["Cost"].ToFloat()));

我该怎么做?

1 个答案:

答案 0 :(得分:3)

我想你想要这个:

.Select(a => new myType 
            { 
               anId = a.Key, 
               aCost = a.Sum(p => p["Cost"].ToFloat())
            })