Count items in List(Of structure) using predicate in .NET 2.0/VB.NET

半腔热情 提交于 2019-12-06 14:52:51

You want List.LongCount.

Dim CarList As New List(Of Car)
Dim Model As String = "Toyota"
Dim ToyotaCount As Long = CarList.LongCount(Function(car) car.Name = Model)
Dim toyotas As Integer = carList.Count(Function(c) c.Name = "Toyota")

Here you go.

 var count = carList.Count(x => x.Name == "Toyota");

The syntax is blatantly wrong, but something like this:

Dim toyotas as Integer;
toyotas = 0;
foreach(car c in listcars){
    if(c.Name == "toyota")//make sure to do string comparison here.
        toyotas++;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!