C# 中的 AsQueryable()
csharpprogrammingserver side programming更新于 2025/9/14 18:34:00
AsQueryable() 方法用于获取 IQueryable 引用。
让我们看一个求整数值之和的示例。
首先,设置一个整数数组。
var arr = new int[] { 100, 200, 300, 400 };
现在要求和,请使用 Queryable Sum() 和 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

