Enumerable.ToList(TSource) 方法
来源:互联网 发布:无线打印服务器 mac 编辑:程序博客网 时间:2024/05/22 06:27
从 IEnumerable(TSource) 创建一个 List(TSource) 。
命名空间: System.Linq source 为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)。 ToList(TSource)(IEnumerable(TSource) 方法强制进行直接查询计算,并返回一个包含查询值的 (T) 。可将此方法追加到您的查询,以获得查询结果的缓存副本。 ToArray(TSource)具有类似行为,但它返回一个数组,而非一个 List(T) 。 下面的代码示例演示如何使用 ToList(TSource) 强制进行直接查询计算并返回一个包含查询结果的 List(T) 。
程序集: System.Core(在 System.Core.dll 中) 异常 条件 ArgumentNullException' Create an array of strings.Dim fruits() As String = _ {"apple", "passionfruit", "banana", "mango", _ "orange", "blueberry", "grape", "strawberry"}' Project the length of each string and ' put the length values into a List object.Dim lengths As List(Of Integer) = _ fruits _ .Select(Function(fruit) fruit.Length) _ .ToList()' Display the results.Dim output As New System.Text.StringBuilderFor Each length As Integer In lengths output.AppendLine(length)NextMsgBox(output.ToString())' This code produces the following output:'' 5' 12' 6' 5' 6' 9' 5' 10
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*/
<ExtensionAttribute> _Public Shared Function ToList(Of TSource) ( _ source As IEnumerable(Of TSource) _) As List(Of TSource)
Dim source As IEnumerable(Of TSource)Dim returnValue As List(Of TSource)returnValue = source.ToList()
public static List<TSource> ToList<TSource>( this IEnumerable<TSource> source)
[ExtensionAttribute]public:generic<typename TSource>static List<TSource>^ ToList( IEnumerable<TSource>^ source)
J# 支持使用泛型 API,但是不支持新泛型 API 的声明。
JScript 不支持泛型类型或方法。
类型参数
- TSource
source 中的元素的类型。
参数
- source
- 类型:System.Collections.Generic..::.IEnumerable (TSource)
要从其创建 List(T) 的 IEnumerable(T) 。
返回值
类型:System.Collections.Generic..::.List (TSource)一个包含输入序列中元素的 List(T) 。
使用说明
在 Visual Basic 和 C# 中,可以在 IEnumerable(TSource)类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。有关更多信息,请参见 扩展方法 (Visual Basic)或 扩展方法(C# 编程指南)。- Enumerable.ToList(TSource) 方法
- Enumerable.ToList<TSource> 方法
- 使用Enumerable.SequenceEqual<TSource> 方法 (IEnumerable<TSource>, IEnumerable<TSource>)判断两个集合是否相同
- Enumerable
- Enumerable.OfType<TResult> 方法 (IEnumerable)
- linq中的tolist()方法什么意思
- c#扩展方法奇思妙:Enumerable.Cast应用
- 浅谈 System.Linq.Enumerable.AsEnumerable 方法
- .net Enumerable类型的方法的一些理解
- 关于.net Enumerable的一些方法的理解
- Arrays.toList
- numpy tolist()
- numpy tolist()
- numpy tolist()
- 【Python】tolist
- Enumerable#reject
- Enumerable#any?
- Enumerable#find_all
- 中国军队在马来鲜为人知战记
- 在虚拟机Linux中挂载Windows文件夹
- Array 类
- 笨拙的DevExpress资源本地化过程
- Js跳转页面
- Enumerable.ToList(TSource) 方法
- 标准C++类型转换符
- C对文件操作的小结
- Eclipse之烦恼
- 四川首个电子商务门户7日运营
- FZU 1706 括号表达式
- Delphi 调用.NET(C#) Web Service
- 如何DIY一台闪存型MP4播放器
- 英语学习网站