Declare and initialize a list.
var products = new List <string>();
products.Add("Accessories");
products.Add("Clothing");
products.Add("Footwear");To get the size, use the Capacity property.
products.Capacity
Now let us see the complete code to find the size of a list.
Example
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(string[] args) {
var products = new List <string>();
products.Add("Accessories");
products.Add("Clothing");
products.Add("Footwear");
Console.WriteLine("Our list....");
foreach(var p in products) {
Console.WriteLine(p);
}
Console.WriteLine("Size of list = " + products.Capacity);
}
}Output
Our list.... Accessories Clothing Footwear Size of list = 4