獲取列表中包含的元素數 在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.pswp.cn/news/542665.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542665.shtml
英文地址,請注明出處:http://en.pswp.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.…