C#中的AsQueryable()
AsQueryable()方法用于获取IQueryable引用。
让我们来看一个查找整数值总和的示例。
首先,设置一个整数数组。
var arr = new int[] { 100, 200, 300, 400 };现在要找到总和,请使用QueryableSum()和AsQueryable()方法。
Queryable.Sum(arr.AsQueryable());
以下是完整的代码。
示例
using System;
using System.Linq;
class Demo {
static void Main() {
var arr = new int[] { 100, 200, 300, 400 };
int res = Queryable.Sum(arr.AsQueryable());
Console.WriteLine("Sum: "+res);
}
}输出结果
Sum: 1000
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短