List<T>

 

命名空间:  System.Linq
程序集:  System.Core(在 System.Core.dll 中)

语法
 
 
public static List<TSource> ToList<TSource>(
	this IEnumerable<TSource> source
)

类型参数

TSource

source 中的元素的类型。

参数

source
类型:System.Collections.Generic.IEnumerable<TSource>
IEnumerable<T>

返回值

类型:System.Collections.Generic.List<TSource>
List<T>

使用说明

在 Visual Basic 和 C# 中,可以在 IEnumerable<TSource> 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。有关详细信息,请参阅扩展方法 (Visual Basic)扩展方法(C# 编程指南)
异常
 
异常 条件
ArgumentNullException

备注
 

可将此方法追加到您的查询,以获得查询结果的缓存副本。

List<T>

示例
 

List<T>

 
string[] fruits = { "apple", "passionfruit", "banana", "mango", 
                                  "orange", "blueberry", "grape", "strawberry" };

            List<int> lengths = fruits.Select(fruit => fruit.Length).ToList();

            foreach (int length in lengths)
            {
                Console.WriteLine(length);
            }

            /*
             This code produces the following output:

             5
             12
             6
             5
             6
             9
             5
             10
            */

 

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2021-10-23
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-06-21
  • 2021-09-20
  • 2021-06-09
  • 2021-10-29
  • 2022-12-23
相关资源
相似解决方案