从列表中获取对象的数量?
public class Agenda
{
public string StartDate;
public string EndDate;
public string Id;
}
public Class Appointments
{
public Agenda agenda;
。
public class ViewModel
我
List<Appointments> collection = new List<Appointments>();
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "1234567" } );
collection.Add(new Agenda { StartDate = "date2" , EndDate = "date2", Id= "1234567" } );
collection.Add(new Agenda { StartDate = "date3" , EndDate = "date3", Id= "2222222" } );
collection.Add(new Agenda { StartDate = "date4" , EndDate = "date4", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date5" , EndDate = "date5", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "1234567" } );
}
希望 Linq 解决方案从 Viewmodel *Appointement* 属性获取 议程 的数量,
例如 Id = "1234567" 列表中有 3 个议程对象
Id = "3333333" has 3 Agenda object in List
Id = "2222222" has 2 Agenda object in List
enter code here
public class Agenda
{
public string StartDate;
public string EndDate;
public string Id;
}
public Class Appointments
{
public Agenda agenda;
}
public class ViewModel
{
List<Appointments> collection = new List<Appointments>();
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "1234567" } );
collection.Add(new Agenda { StartDate = "date2" , EndDate = "date2", Id= "1234567" } );
collection.Add(new Agenda { StartDate = "date3" , EndDate = "date3", Id= "2222222" } );
collection.Add(new Agenda { StartDate = "date4" , EndDate = "date4", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date5" , EndDate = "date5", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "3333333" } );
collection.Add(new Agenda { StartDate = "date1" , EndDate = "date1", Id= "1234567" } );
}
I want Linq solution to get the number of Agendas from the Viewmodel *Appointement* property
eg. Id = "1234567" has 3 Agenda object in List
Id = "3333333" has 3 Agenda object in List
Id = "2222222" has 2 Agenda object in List
enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(从 ViewModel.collection 中的 a.Id.Equals("1234567") 选择 a).Count();
(from a in ViewModel.collection where a.Id.Equals("1234567") select a).Count();