How to count the number of items in a C# list?

CsharpProgrammingServer Side Programming

Use the Array.Count property in C# to count the number of items in a list in C# −

Set the list

List<string> myList = new List<string>() {
   "electronics",
   "clothing",
   "appliances",
   "accessories"
};

Now count the number of items in a list in C# −

myList.Count

The following is the complete code to count the number of items in a list −

Example

using System;
using System.Collections.Generic;

class Program {
   static void Main() {
      List myList = new List() {
         "electronics",
         "clothing",
         "appliances",
         "accessories"
      };
      Console.WriteLine(myList.Count);
   }
}
raja
Published on 13-Aug-2018 17:20:13
Advertisements