Count integers in a list

I have a set of integers in a list. I know I can do something like this to get a specific event:

List<ResultsViewModel> list = data.ToList<ResultsViewModel>(); Response.Write(list[2].NoNotEncounterBarriersResult); 

But how can I go through the loop and count the number of instances of list[i].NoNotEncounterBarriersResult = true and return the result as an integer?

+4
source share
3 answers

Use Count

 var count = list.Count(item => item.NoNotEncounterBarriersResult) 

http://msdn.microsoft.com/en-us/library/bb535181.aspx

+5
source

Use Count :

 int count = list.Count(x => x.NoNotEncounterBarriersResult); 

From the documentation:

Returns a number representing how many elements in the specified sequence satisfy the condition.

+3
source
 int count = list.Count(x => x.NoNotEncounterBarriersResult); 

How to use Linq counter to get an invoice?

0
source

All Articles