在.NET 2.0/VB.NET中使用谓词对List(Of structure)中的项目进行计数 [英] Count items in List(Of structure) using predicate in .NET 2.0/VB.NET
本文介绍了在.NET 2.0/VB.NET中使用谓词对List(Of structure)中的项目进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要计算.NET 2.0中 List(Of Structure)
中符合条件的项目.例如:
I need to count the items that meet a criteria in a List(Of Structure)
in .NET 2.0. For example:
Dim listcars as New List(Of car)
Structure car
Dim Name as String
Dim year as Integer
End structure
现在我需要计算所有名称为Toyota等的汽车.我该怎么做?
Now I need to count all cars with name Toyota, etc.. How do I do it?
推荐答案
您要 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)
这篇关于在.NET 2.0/VB.NET中使用谓词对List(Of structure)中的项目进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文