如何计算 C# 列表中的项目数?
使用 C# 中的 Array.Count 属性来计算 C# 中列表中的项目数 −
设置列表
List<string> myList = new List<string>() {
"electronics",
"clothing",
"appliances",
"accessories"
};现在计算 C# 中列表中的项目数 −
myList.Count
以下是计算列表中项目数的完整代码 −
示例
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List myList = new List() {
"electronics",
"clothing",
"appliances",
"accessories"
};
Console.WriteLine(myList.Count);
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP