以 64 位帶符號整數形式返回序列中的總元素數(C#)
首先,設定一個字串陣列。
string[] num = { "One", "Two", "Three", "Four", "Five"};使用 Linq LongCount 方法來獲取元素的計數。
num.AsQueryable().LongCount();
以下是完整的程式碼 -
示例
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
string[] num = { "One", "Two", "Three", "Four", "Five"};
long res = num.AsQueryable().LongCount();
Console.WriteLine("{0} elements", res);
}
}輸出
5 elements
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP