如何在C#中查找列表的大小?
声明并初始化一个列表。
var products = new List <string>();
products.Add("Accessories");
products.Add("Clothing");
products.Add("Footwear");要获取大小,请使用Capacity属性。
products.Capacity
现在,让我们查看完整的代码以查找列表的大小。
示例
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);
}
}输出结果
Our list.... Accessories Clothing Footwear Size of list = 4
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短