EvictingDictionary<TKey, TValue>.Enumerator Struct
Definition
Enumerates the live entries of an EvictingDictionary<TKey, TValue> in policy order without allocating.
public struct EvictingDictionary<TKey, TValue>.Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IEnumerator, IDisposable
- Implements
-
IEnumerator<KeyValuePair<TKey, TValue>>
- Inherited Members
- Extension Methods
Remarks
Use the foreach statement to enumerate the dictionary rather than using this struct directly.
The enumerator captures the dictionary's version - and, when time-based expiration is configured, a single clock snapshot - on construction. Any mutation of the dictionary (including reads that reposition entries under the LeastRecentlyUsed, MostRecentlyUsed, or LeastFrequentlyUsed policies) invalidates the enumerator and causes MoveNext() or Reset() to throw InvalidOperationException. Expired entries are filtered against the captured clock snapshot and are never removed by enumeration.
Properties
Current
Gets the element in the collection at the current position of the enumerator.
public readonly KeyValuePair<TKey, TValue> Current { get; }
Property Value
- KeyValuePair<TKey, TValue>
The element in the collection at the current position of the enumerator.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public readonly void Dispose()
MoveNext()
Advances the enumerator to the next element of the collection.
public bool MoveNext()
Returns
- bool
true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
Exceptions
- InvalidOperationException
The collection was modified after the enumerator was created.
Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
public void Reset()
Remarks
Restarts the walk from the beginning against the same version and clock snapshot captured at construction.
Exceptions
- InvalidOperationException
The collection was modified after the enumerator was created.
- NotSupportedException
The enumerator does not support being reset.
Explicit Interface Implementations
IEnumerator.Current
Gets the element in the collection at the current position of the enumerator.
readonly object IEnumerator.Current { get; }
Returns
- object
The element in the collection at the current position of the enumerator.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |