Enumerable.TryGetNonEnumeratedCount<TSource> 方法

定义

尝试在不强制枚举的情况下确定序列中的元素数。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static bool TryGetNonEnumeratedCount(System::Collections::Generic::IEnumerable<TSource> ^ source, [Runtime::InteropServices::Out] int % count);
public static bool TryGetNonEnumeratedCount<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, out int count);
static member TryGetNonEnumeratedCount : seq<'Source> * int -> bool
<Extension()>
Public Function TryGetNonEnumeratedCount(Of TSource) (source As IEnumerable(Of TSource), ByRef count As Integer) As Boolean

类型参数

TSource

source 的元素类型。

参数

source
IEnumerable<TSource>

包含要计数的元素的序列。

count
Int32

此方法返回时,包含元素 source数;如果未枚举无法确定计数,则为 0。

返回

Boolean

true 如果可以在不枚举的情况下确定计数 source ,则为 ;否则为 false

注解

该方法执行一系列类型测试,标识可以确定其计数而不枚举的常见子类型。 ICollection<T>这包括 LINQ 实现中使用的内部ICollection类型。

该方法通常是一个常量时间操作,但最终这取决于基础集合实现的复杂性特征。

适用于