方法'select'接受2个参数

本文关键字:参数 2个 select 方法 接受 | 更新日期: 2023-09-27 18:19:25

我试图从我的查询中获得两个值,但我得到这个错误:

"没有重载方法'select'有两个参数"

下面是我的代码:
    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()));

我该怎么做呢?

方法'select'接受2个参数

我想你想要这个:

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