博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取列表中包含的元素数 在C#中
阅读量:2532 次
发布时间:2019-05-11

本文共 2014 字,大约阅读时间需要 6 分钟。

Given a list, and we have to count its total number of elements using List.Count property.

给定一个列表,我们必须使用List.Count属性计算其元素总数

C#清单 (C# List)

A list is used to represent the list of the objects, it is represented as List<T>, where T is the type of the list objects/elements.

列表用于表示对象的列表,它表示为List <T> ,其中T是列表对象/元素的类型。

A list is a class which comes under System.Collections.Generic package, so we have to include it first.

列表是System.Collections.Generic包下的一个类,因此我们必须首先包含它。

List.Count属性 (List.Count property)

Count is a property of List class; it returns the total number of elements of a List.

CountList类的属性; 它返回List的元素总数。

Syntax:

句法:

List_name.Count;

Here, List_name is the name of input/source list whose elements to be counted.

在此, List_name是要计算其元素的输入/源列表的名称。

Example:

例:

Input:    //an integer list    List
int_list = new List
{ 10, 20, 30, 40, 50, 60, 70 }; //a string list List
str_list = new List
{ "Manju", "Amit", "Abhi", "Radib", "Prem" }; Function call: int_list.Count; str_list.Count; Output: 7 5

C#程序计算列表中元素的总数 (C# program to count the total number of elements of a List)

using System;using System.Text;using System.Collections.Generic;namespace Test{
class Program {
static void Main(string[] args) {
//an integer list List
int_list = new List
{
10, 20, 30, 40, 50, 60, 70 }; //a string list List
str_list = new List
{
"Manju", "Amit", "Abhi", "Radib", "Prem" }; //printing total number of elements Console.WriteLine("Total elements in int_list is: " + int_list.Count); Console.WriteLine("Total elements in str_list is: " + str_list.Count); //hit ENTER to exit Console.ReadLine(); } }}

Output

输出量

Total elements in int_list is: 7Total elements in str_list is: 5

翻译自:

转载地址:http://yzxzd.baihongyu.com/

你可能感兴趣的文章
在Qsys中创建用户自定义IP
查看>>
【leetcode】Container With Most Water
查看>>
Python -- machine learning, neural network -- PyBrain 机器学习 神经网络
查看>>
一道dp题目
查看>>
mysql中间件研究(tddl atlas cobar sharding-jdbc)
查看>>
Cast-128 加密算法和 MyPassWord 的破解
查看>>
4.28下午 听力611
查看>>
ActiveMQ学习笔记(1)----初识ActiveMQ
查看>>
Java与算法之(2) - 快速排序
查看>>
Windows之IOCP
查看>>
机器学习降维之主成分分析
查看>>
CTP2交易所成交回报
查看>>
WebSocket & websockets
查看>>
《机器学习实战》学习笔记第二章 —— K-近邻算法
查看>>
uni-app 引入本地iconfont的正确姿势以及阿里图标引入
查看>>
DSB
查看>>
Java中的阻塞队列
查看>>
前端软件sublime的一些常用快捷键
查看>>
openssl 升级
查看>>
2017.10.30 天晴 昨天十公里没减肥
查看>>