![](/img/trans.png)
[英]Linq to get list of custom objects where a certain value contained within dictionary property equals a specific value
[英]Linq query get sum from list where certain property equals to
我有以下課程:
活動
時間(整數)
已檢查(字符)
示例列表:
活動1:時間= 5已檢查= y
活動2:時間= 5已檢查= n
活動3:時間= 5已檢查= y
在我的活動列表中,我想選擇具有選中值“ y”的活動的總時間(以分鍾為單位)。
在上述情況下,我的總數應為10。
我使用了以下內容:
int minutes = i.Activities.Sum(i.Activities.Where(x => x.Checked == 'y'));
這返回
“無法從System.Collections.Generic.IEnumerable轉換為System.Func”
我究竟做錯了什么?
您要預先過濾結果:
int minutes = i.Activities.Where(x => x.Checked == 'y').Sum(x => x.Time);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.