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.
  1. 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.
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. // Create a list of strings
  10. List<string> AuthorList = new List<string>();
  11. AuthorList.Add("Mahesh Chand");
  12. AuthorList.Add("Praveen Kumar");
  13. AuthorList.Add("Raj Kumar");
  14. AuthorList.Add("Nipun Tomar");
  15. AuthorList.Add("Dinesh Beniwal");
  16. // Count
  17. Console.WriteLine($"Count: {AuthorList.Count}");
  18. }
  19. }
  20. }
The output from above code listing is shown in below figure.
count in C# List
Next >> C# List Tutorial