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。

傳回

true 如果的計數 source 可以判斷而不列舉,則為 ,否則為 false

備註

方法會執行一系列類型測試,識別可判斷其計數而不列舉的常見子類型。 ICollection<T>這包括 LINQ 實作中使用的、 ICollection和 內部類型。

方法通常是常數時間作業,但最終取決於基礎集合實作的複雜度特性。

適用於