Free Web Development Online Tutorials, Learn to Code
LINQ Count Method Example, Learn LINQ with C#

LINQ Count Method Example

Learn how to use Count method in LINQ using C#, you can get the count of entity in any collection, there is a built-in method to get count in LINQ query syntax.

Count in LINQ C#

Count is Enumerable extension method, it comes under System.Linq namespace. We often use count method to get the total number of items in any collection object.

IEnumerable collection count example
IEnumerable<string> countries = new List<string> { "India", "USA", "UK", "Canada", "Australia" };
int count = countries.Count();  

Count with Predicate example
Count the total number of items in any specified predicate

IEnumerable<int> items = new List<int> { 10, 20, 30, 40, 50, 100 }; int count = items.Where(x => x < 49).Count();

Count with Query Syntax

IEnumerable<int> items = new List<int> { 10, 20, 30, 40, 50, 100 };           
int count = (from n in items select n).Count();
Comment
Name
Email
Website
Subscribe
 
Learn LINQ .Net

LINQ Count method example in C#- Count in LINQ query syntax

linq Interview Questions Answers

LINQ C# examples | Join Asp.net MVC Course