LINQ to Int Array

  Total Views : 131
  Comments : 0
 
  Keywords : Linq to arrays example in c# / vb.net, How to write linq queries on integer array to get required data in c# / vb.net with example, Use linq to get integer elements from array list example

Here we will learn LINQ to Int Array in c#, vb.net with example and how to write LINQ queries to get elements from integer array in c#, vb.net with example.

LINQ to Int Array

LINQ to int array means writing LINQ queries on an integer array to get required elements from integer array elements. By using LINQ queries on integer arrays we can get required data from integer array without writing much code. 

Syntax of LINQ to Int Array

Following is the syntax of writing LINQ queries on integer arrays to get required elements from array collection.

 

C# Code

 

IEnumerable<int> result = from a in numarr

                                           select a;

VB.NET Code

 

Dim result As IEnumerable(Of Integer) = From a In numarr

If you observe above syntax we written LINQ query to get data from “numarr” integer array.

Example of LINQ to Int Array

Following is the example of LINQ to Int Array to get elements from the sequence where elements value greater than 10 and less than 200.

 

C# Code

 

using System;

using System.Collections.Generic;

using System.Linq;

 

namespace Linqtutorials

{

class Program

{

static void Main(string[] args)

{

int[] numarr = { 1, 6, 9, 10, 50, 60, 100, 200, 300 };

IEnumerable<int> result = from a in numarr

where a > 10 && a < 200

select a;

foreach (int item in result)

{

Console.WriteLine(item);

}

Console.ReadLine();

}

}

}

VB.NET Code

 

Module Module1

Sub Main()

Dim numarr As Integer() = {1, 6, 9, 10, 50, 60, 100, 200, 300}

Dim result As IEnumerable(Of Integer) = From a In numarr Where a > 10 AndAlso a < 200

For Each item As Integer In result

Console.WriteLine(item)

Next

Console.ReadLine()

End Sub

End Module

If you observe above code we used LINQ query on “numarr” integer array to get elements whose value greater than 10 and less than 200.

Output of LINQ to Int Array Example

Following is the result of LINQ to Int Array Example.

 

50

60

100

This is how we can use LINQ queries with integer arrays to get required data in c#, vb.net with example.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User