3 回答
TA贡献1780条经验 获得超3个赞
也使用代替任意值类型:当您实例化list_TA时,它需要DateTime SAMPLE_TIME,字符串WAIT_CLASS,双倍计数作为参数传递。为了解决这个问题,请引入无参数构造函数。new list_TA
public class list_TA
{
public DateTime SAMPLE_TIME { get; set; }
public string WAIT_CLASS { get; set; }
public double COUNT { get; set; }
public list_TA()
{
}
public list_TA(DateTime SAMPLE_TIME, string WAIT_CLASS, double COUNT)
{
this.SAMPLE_TIME = SAMPLE_TIME;
this.WAIT_CLASS = WAIT_CLASS;
this.COUNT = COUNT;
}
}
TA贡献1827条经验 获得超7个赞
您可以在 LINQ 中选择list_TA,如下所示:
var test = listASH
.Select(g => new
{
SAMPLE_TIME = statiClass.By15Seconds(Convert.ToDateTime(g.SAMPLE_TIME)),
WAIT_CLASS = g.WAIT_CLASS,
COUNT = 0,
}).GroupBy(x => new { x.SAMPLE_TIME, x.WAIT_CLASS })
.Select(y => new list_TA
{
SAMPLE_TIME = y.Key.SAMPLE_TIME,
WAIT_CLASS = y.Key.WAIT_CLASS,
COUNT = Math.Round(y.Count() / 15.0, 2),
}).ToList();
TA贡献1840条经验 获得超5个赞
匿名类不能隐式转换为任何其他类型。
您需要使用而不是new list_TAnew
将默认构造函数添加到类中,并使用以下代码list_TA
.Select(y => new list_TA
{
SAMPLE_TIME = y.Key.SAMPLE_TIME,
WAIT_CLASS = y.Key.WAIT_CLASS,
COUNT = Math.Round(y.Count() / 15.0, 2),
});
或
.Select(y => new list_TA (
y.Key.SAMPLE_TIME,
y.Key.WAIT_CLASS,
Math.Round(y.Count() / 15.0, 2)
));
- 3 回答
- 0 关注
- 90 浏览
添加回答
举报