首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在C#中将IEnumerable <T>转换为List <T>?

要在C#中将IEnumerable <T>转换为List <T>,您可以使用以下方法:

  1. 使用Linq库中的ToList()方法:using System.Linq; IEnumerable<T> enumerable = ...; List<T> list = enumerable.ToList();
  2. 使用List <T>的构造函数:IEnumerable<T> enumerable = ...; List<T> list = new List<T>(enumerable);
  3. 使用foreach循环遍历IEnumerable <T>并将每个元素添加到List <T>中:IEnumerable<T> enumerable = ...; List<T> list = new List<T>(); foreach (T item in enumerable) { list.Add(item); }

这些方法都可以将IEnumerable <T>转换为List

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券