Home > database >  Get the count by type in a List
Get the count by type in a List

Time:02-02

I am having trouble getting the count by its type.

Object

enter image description here

How do I get the count of Home (PartnerIntegrationbTesting.Context.Home)? There are 4 items in the List (quoteList.Products)

CodePudding user response:

Use .Count() with a filtering function. is will test if the left-hand object is the type specified on the right.

var countOfHomeProducts = quoteList.Products
   .Count(p => p is PartnerIntegrationbTesting.Context.Home);
  •  Tags:  
  • Related