无涯教程-Linq Asnumerable运算符

41 阅读1分钟

在LINQ中,AsEnumerble()方法用于将给定列表的特定类型转换为其IEnumerable()等价类型。

LINQ AsEnumerable()方法的语法

C#代码

var result = numarray.AsEnumerable();

In the above syntax, we are converting the list of "numarray" to IEnumerable type.

LINQ AsEnumerable()方法示例

下面是使用LINQAsEnumerable方法将列表转换为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();
        }
        }
}

In the above example, we are converting the list of "NumArray" to IEnumerable type by using the AsEnumerable method.

输出:

LINQ AsEnumrable() Method




参考链接

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