在LINQ中,AsEnumerble()方法用于将给定列表的特定类型转换为其IEnumerable()等价类型。
C#代码
var result = numarray.AsEnumerable();
In the above syntax, we are converting the list of "numarray" to IEnumerable type.
下面是使用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.
输出:
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕