以 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