C# List<T> class provides methods and properties to create a list of objects (classes).
List is a generic class. You must import the following namespace before using the List<T> class.
- using System.Collections.Generic;
How to get number of items in a List with C#
The Count property gets the total actual number of items in list.
The following code snippet display number of items in a list.
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Create a list of strings
- List<string> AuthorList = new List<string>();
- AuthorList.Add("Mahesh Chand");
- AuthorList.Add("Praveen Kumar");
- AuthorList.Add("Raj Kumar");
- AuthorList.Add("Nipun Tomar");
- AuthorList.Add("Dinesh Beniwal");
- // Count
- Console.WriteLine($"Count: {AuthorList.Count}");
- }
- }
- }
The output from above code listing is shown in below figure.
Next >> C# List Tutorial

Rajan MishraPosted Oct 8, 2018, 3:44 AM
Does this work with c# 5.0?.... although nice tip thanks sir
Rushi MehtaPosted Oct 8, 2018, 3:15 AM
Perfect Article to count number of items