LINQ to int Array意味着在整数数组上编写LINQ查询,以便从整数数组元素中获取所需的元素。通过在整数数组上使用LINQ查询,无涯教程可以在不编写大量代码的情况下从整数数组中获得所需的数据。
编写整数数组上的LINQ查询以从数组集合中获取所需元素的语法。
IEnumerableresult = from a in numarr1 select a;
在上述语法中,编写了 LINQ 查询以从“numarr”整数数组中获取数据。
下面是LINQ to int Array的示例,用于从元素值大于10小于200的序列中获取元素。
using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Programme2 { static void Main(string[] args) { //创建一个 int 类型的数组 numarray int[] numarray = { 1, 6, 9, 10, 50, 60, 100, 200, 300 }; /*编写 LINQ 查询以从数值大于 10 且小于 200 的 numarray*/ IEnumerableresult = from a in numarray where a > 10 && a
在上面的代码中,无涯教程使用 LINQ 查询“numarray”整数数组来获取值大于 10 且小于 200 的元素。
输出:
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)