日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/11 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取列表中包含的元素数 在C#中 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

給定一個列表,我們必須使用List.Count屬性計算其元素總數(shù) 。

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.

Count是List類的屬性; 它返回List的元素總數(shù)。

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 listList<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:75

C#程序計算列表中元素的總數(shù) (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 listList<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 elementsConsole.WriteLine("Total elements in int_list is: " + int_list.Count);Console.WriteLine("Total elements in str_list is: " + str_list.Count);//hit ENTER to exitConsole.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

總結(jié)

以上是生活随笔為你收集整理的获取列表中包含的元素数 在C#中的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。