无涯教程-LINQ - 整数数组(Int Array)

52 阅读1分钟

LINQ to int Array意味着在整数数组上编写LINQ查询,以便从整数数组元素中获取所需的元素。通过在整数数组上使用LINQ查询,无涯教程可以在不编写大量代码的情况下从整数数组中获得所需的数据。

LINQ to INT数组的语法

编写整数数组上的LINQ查询以从数组集合中获取所需元素的语法。

IEnumerable result = from a in numarr1
                                  </span><span class="kwd">select</span><span class="pln"> a</span><span class="pun">;</span></int></pre></div>

在上述语法中,编写了 LINQ 查询以从“numarr”整数数组中获取数据。

LINQ到INT数组的示例

下面是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/ IEnumerable result = from a in numarray where a > 10 && a

在上面的代码中,无涯教程使用 LINQ 查询“numarray”整数数组来获取值大于 10 且小于 200 的元素。

输出:

LINQ to Int Array

参考链接

www.learnfk.com/linq/linq-t…