[英]Finding total number of items in multiple instances of a collection & binding count to Textblock
[英]Count Number of items in a collection
如何計算等於某個值的項目並將其放置在標簽中?
class Conversation
{
public string Id { get; set; }
public int Readen { get; set; }
public string Recipient { get; set; }
}
在“已讀”屬性中,存在等於“ 1”或“ 0”的值。 如何計算每個等於“ 1”的Readen?
更新;
在對話填充后嘗試了此調用:
private void CountUnread() {
int i = 0;
Conversation cs = new Conversation();
if (cs.Readen == "1") {
i++;
}
MessageBox.Show(i.ToString());
}
MessageBox顯示零
使用Linq ,或更確切地說,使用Enumerable.Count方法:
IEnumerable<Conversation> items = ...
...
var count = items.Count(c => c.Readen == 1);
像這樣的東西
Conversation cs = new Conversation();
//如果您在另一個類中,請創建實例
if (cs.Readen.Equals(1)) { //Your Statements Here... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.