Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Đếm số phần tử trong List C#


Dùng property Count.

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

Ví dụ

using System;
using System.Collections.Generic;
class Program {
    static void Main() {
        List<string> myList = new List<string>() { "electronics", "clothing", "appliances", "accessories" };
        Console.WriteLine(myList.Count);
    }
}