获取列表中包含的元素数 在C#中

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> int_list = new List<int> { 10, 20, 30, 40, 50, 60, 70 };
//a string list 
List<string> str_list = new List<string>{
"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> int_list = new List<int> { 10, 20, 30, 40, 50, 60, 70 };
//a string list 
List<string> str_list = new List<string>{
"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: 7
Total elements in str_list is: 5

翻译自: https://www.includehelp.com/dot-net/gets-the-number-of-elements-contained-in-the-list-t-in-c-sharp.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542665.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

I00037 亏数(Deficient number)

数论中&#xff0c;若一个正整数除了本身之外所有因子之和比此数自身小&#xff0c;则称此数为亏数。亏数&#xff08;Deficient number&#xff09;也称为缺数&#xff0c;参见百度百科_亏数&#xff0c;或参见维基百科的Deficient number。亏数在OEIS中的数列号为A005100。 问…

hashmap转红黑树的阈值为8_面试必考的 HashMap,这篇总结到位了

点击蓝色“JavaKeeper”关注我哟加个“星标”&#xff0c;一起成长&#xff0c;做牛逼闪闪的技术人1 概述HashMap是基于哈希表实现的,每一个元素是一个key-value对,其内部通过单链表解决冲突问题,容量不足(超过了阀值)时,同样会自动增长.HashMap是非线程安全的,只适用于单线程环…

linux用户组管理命令_Linux用户和组命令能力问题和解答

linux用户组管理命令This section contains Aptitude Questions and Answers on Linux User and Group Commands. 本节包含有关Linux用户和组命令的 Aptitude问答。 1) Which of the following commands is used to create a new user in the Linux operating system? create…

Failed to start firewalld.service: Unit firewalld.service is masked.

2019独角兽企业重金招聘Python工程师标准>>> FireWall in Centos 7 masked How to resolve the error message belowFailed to issue method call: Unit firewalld.service is masked. The main reason a service is masked is to prevent accidental starting or e…

mysql第二个索引_MySQL高级第二章——索引优化分析

一、SQL性能下降原因1.等待时间长&#xff1f;执行时间长&#xff1f;可能原因&#xff1a;查询语句写的不行索引失效(单值索引、复合索引)CREATE INDEX index_user_name ON user(name);(底层做了一个排序)CREATE INDEX index_user_nameEmail ON user(name,email);查询关联join…

递归反转链表改变原链表吗_在不使用递归的情况下找到链表的长度

递归反转链表改变原链表吗Solution: 解&#xff1a; Algorithm to find length 查找长度的算法 Input: 输入&#xff1a; A singly linked list whose address of the first node is stored in a pointer, say head. 一个单链表 &#xff0c;其第一个节点的地址存储在指针(例…

西瓜仿站高手v1.08官方正式版

2019独角兽企业重金招聘Python工程师标准>>> 西瓜仿站高手是一款绿色好用的由追风网络出品的网站模板批量下载软件&#xff0c;西瓜仿站高手是一款仿站工具&#xff0c;仿站神器。软件功能强大&#xff0c;能够帮你轻松帮你下载任意网站、任意模板&#xff0c;并且速…

用hundred造句子_八个有趣的开学破冰游戏,线上线下都能用

知道大家最近都很忙&#xff0c;所以省略开篇&#xff0c;直接上正题——开学“破冰游戏”走起&#xff01;一、你比划我来猜把词语展示在PPT上&#xff0c;猜词的同学背对PPT&#xff0c;其他同学可以看到词语并且用身体动作把词语表现出来&#xff0c;直到猜词的同学可以把词…

java 执行顺序_Java代码执行顺序

程序中代码执行的顺序非常重要&#xff0c;稍有不慎便会是程序运行出错&#xff0c;那么我将结合实例来分析代码中的执行。名词解释首先了解几个名词&#xff1a;非静态代码块直接由 { } 包起来的代码&#xff0c;称为非静态代码块静态代码块直接由 static { } 包起来的代码&am…

mysql 包含的那些文件

*.frm是描述了表的结构 *.MYD保存了表的数据记录 *.MYI则是表的索引 ibd是MySQL数据文件、索引文件&#xff0c;无法直接读取。 转载于:https://www.cnblogs.com/07byte/p/5823667.html

math 计算float_Java Math类静态float min(float f1,float f2)与示例

math 计算float数学类静态浮点数min(float f1&#xff0c;float f2) (Math Class static float min(float f1 , float f2) ) This method is available in java.lang package. 此方法在java.lang包中可用。 This method is used to return the minimum one of both the given a…

vector 不初始化时什么状态_Vue原理解析(三):初始化时created之前做了什么?...

让我们继续this._init()的初始化之旅&#xff0c;接下来又会执行这样的三个初始化方法&#xff1a;initInjections(vm) initState(vm) initProvide(vm)5. initInjections(vm): 主要作用是初始化inject&#xff0c;可以访问到对应的依赖。inject和provide这里需要简单的提一下&a…

switch 字符串 java_JDK7新特性switch支持字符串

在JDK7中,switch语句的判断条件增加了对字符串类型的支持。由于字符串的操作在编程中使用频繁,这个新特性的出现为Java编程带来了便利。接下来通过一个案例演示一下在switch语句中使用字符串进行匹配。public class Example {public static void main(String[] args) {String w…

cisco packet tracer路由器配置_【干货】思科交换机路由器怎么配置密码?

今天带大家看看如何在思科的交换机路由器当中配置安全特性&#xff0c;也就是密码的配置方式。在学习配置之前&#xff0c;我们先回顾一下密码相关知识。密码学是研究信息系统安全保密的科学。人类有记载的通信密码始于公元前400年&#xff0c;古希腊人是置换密码学的发明者。密…

perl 哈希数组的哈希_使用哈希检查两个数组是否相似

perl 哈希数组的哈希Prerequisite: Hashing data structure 先决条件&#xff1a; 哈希数据结构 Problem statement: 问题陈述&#xff1a; Check whether two arrays are similar or not using the hash table. The arrays are of the same size. 使用哈希表检查两个数组是否…

codevs3872 邮递员送信(SPFA)

邮递员送信 时间限制: 1 Sec 内存限制: 64 MB提交: 10 解决: 5[提交][状态][讨论版] 题目描述 有一个邮递员要送东西&#xff0c;邮局在节点1.他总共要送N-1样东西&#xff0c;其目的地分别是2~N。由于这个城市的交通比较繁忙&#xff0c;因此所有的道路都是单行的&#xff0…

java上传csv文件上传_java处理csv文件上传示例详解

前言&#xff1a;示例只是做了一个最最基础的上传csv的示例&#xff0c;如果要引用到代码中去&#xff0c;还需要根据自己的业务自行添加一些逻辑处理。readcsvutil工具类package com.hanfengyeqiao.gjb.utils;import java.io.*;import java.util.*;/*** csv工具类*/public cla…

360更新补丁一直提示正在安装_远程利用POC公布|CVE20200796:微软发布SMBv3协议“蠕虫级”漏洞补丁通告...

更多全球网络安全资讯尽在邑安全www.eansec.com0x00 事件描述2020年3月11日&#xff0c;360CERT监测到有海外厂家发布安全规则通告&#xff0c;通告中描述了一处微软SMBv3协议的内存破坏漏洞&#xff0c;编号CVE-2020-0796&#xff0c;并表示该漏洞无需授权验证即可被远程利用&…

字符串的回文子序列个数_计算给定字符串中回文子序列的数量

字符串的回文子序列个数Problem statement: 问题陈述&#xff1a; Given a string you have to count the total number of palindromic subsequences in the giving string and print the value. 给定一个字符串&#xff0c;您必须计算给定字符串中回文子序列的总数并打印该值…

Linux-破解rhel7-root密码

破解7的密码1.linux16 rd.break2.mount -o remount,rw /sysroot3.chroot /sysroot4.passwd5.touch /.autorelabelexitexit7版本grub菜单加密1.grub2-mkpasswd-pbkdf22.vi /etc/grub.d/40_customset superusers"root"password_pbkdf2 root grub.pbkdf2.sha512.10000.…