Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to count the items that meet a criteria in a list(of structure) in .net 2.0. eg
Dim listcars as new list(or car)
Structure car
   Dim Name as string
   Dim year as integer
End structure

Now i need to count all cars with name toyota etc, how do i do it.
thanks
Posted

Is this what you're looking for?

Understanding Predicate Delegates in C#[^]

C#, List.Find() and Predicates[^]

Hope it helps
 
Share this answer
 
Comments
Cool Smith 26-Jul-11 9:36am    
thanks , but it does not give a clue of how to solve my problem.
Dave Kreskowiak 26-Jul-11 9:56am    
Actually, yes it does, and quite easily solves your problem if you bother to try and understand it.

You can use the information in those links with either a loop or a LINQ expression.

If you're looking for code to be written for you to do this, you've come to the wrong place.

List(T) members (VB.NET)[^]

look at the find and findall methods.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Jul-11 3:18am    
That solves the problem, my 5.
--SA
Simon_Whale 27-Jul-11 3:46am    
Thanks SA :)
Thnaks for all who suggested and contributed,

Here is the solution i found

VB
FoundCar = MyCars.FindAll(Function(item As Car) item.Name = "Toyota").Count
 
Share this answer
 
Comments
Simon_Whale 27-Jul-11 8:52am    
glad to see that you've found the answer with the suggested information

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900