Enumerable.TryGetNonEnumeratedCount<TSource> 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
嘗試判斷序列中的元素數目,而不強制列舉。
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>、 ICollection以及 LINQ 實作中使用的內部型別。
此方法通常為常數時間操作,但最終取決於底層集合實作的複雜度特性。