本文概述
在LINQ中, 使用AsEnumerble()方法将给定列表的特定类型转换为其等效的IEnumerable()类型。
LINQ AsEnumerable()方法的语法
C#代码
var result = numarray.AsEnumerable();
在以上语法中, 我们将” numarray”的列表转换为IEnumerable类型。
LINQ AsEnumerable()方法的示例
这是使用LINQ AsEnumerable方法将列表转换为IEnumerable的示例。
using System;
using System. Collections;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program1
{
static void Main(string[] args)
{
//here we are creating an array NumArray type of int
int[] NumArray = new int[] { 1, 2, 3, 4, 5};
//After applying the AsEnumerable method the output will be store in variable result
var result = NumArray.AsEnumerable();
//Now we will print the value of variable result one by one with the help of foreach loop
foreach (var number in result)
{
Console.WriteLine(number);
}
Console.ReadLine();
}
}
}
在上面的示例中, 我们使用AsEnumerable方法将” NumArray”的列表转换为IEnumerable类型。
输出
