3 回答

TA貢獻1780條經驗 獲得超4個贊
也使用代替任意值類型:當您實例化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條經驗 獲得超8個贊
您可以在 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 關注
- 118 瀏覽
添加回答
舉報