Linq Asnumerable运算符

Linq Asnumerable运算符 首页 / LinQ入门教程 / Linq Asnumerable运算符

在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




祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

iOS开发高手课 -〔戴铭〕

Kafka核心技术与实战 -〔胡夕〕

Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕

从0打造音视频直播系统 -〔李超〕

苏杰的产品创新课 -〔苏杰〕

正则表达式入门课 -〔涂伟忠〕

Spring编程常见错误50例 -〔傅健〕

深入浅出分布式技术原理 -〔陈现麟〕

AI绘画核心技术与实战 -〔南柯〕

好记忆不如烂笔头。留下您的足迹吧 :)