LINQ AsEnumerable() Method

  Total Views : 231
  Comments : 0
 
  Keywords : Asenumerable() method in linq with example using c# / vb.net, How to use asenumerable method in linq to convert given list to ienumerable list type, Linq asenumerable() method in c# / vb.net

Here we will learn linq asenumerable() method with example in c#, vb.net and how to use linq asenumerable list to convert list items to ienumerable list with example in c#, vb.net.

LINQ AsEnumerable() Method

In LINQ AsEnumerable() method is used to convert / cast specific type of given list items to its IEnumerable equivalent type.

Syntax of LINQ AsEnumerable method

Following is the syntax of using LINQ AsEnumerable method to convert give list items to IEnumerable type.

 

C# Code

 

var result = numarray.AsEnumerable();

VB.NET Code

 

Dim result = numarray.AsEnumerable()

If you observe above syntax we are converting “numarray” list / collection to IEnumerable type.

Example of LINQ AsEnumerable() Method

Following is the example of using LINQ AsEnumerable method to convert list of items to IEnumerable type.

 

C# Code

 

using System;

using System.Linq;

 

namespace LINQExamples

{

class Program

{

static void Main(string[] args)

{

int[] numarray = new int[] { 1, 2, 3, 4 };

var result = numarray.AsEnumerable();

foreach (var number in result)

{

Console.WriteLine(number);

}

Console.ReadLine();

}

}

}

VB.NET Code

 

Module Module1

Sub Main()

 

Dim numarray As Integer() = New Integer() {1, 2, 3, 4}

Dim result = numarray.AsEnumerable()

For Each number In result

Console.WriteLine(number)

Next

Console.ReadLine()

End Sub

End Module

If you observe above array we are converting “numarray” list to IEnumerable type by using AsEnumerable() method.

Output of LINQ AsEnumerable() Method Example

Following is the result of LINQ AsEnumerable() method example.

 

1

2

3

4

This is how we can use LINQ AsEnumerable() method to convert list of items to IEnumerable list.

 
 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User