同理,Values屬性枚舉時所需要的枚舉器代碼類似:
ReversibleSortedListValueEnumerator#region ReversibleSortedListValueEnumerator
private sealed class ReversibleSortedListValueEnumerator :
IEnumerator<TValue>, IDisposable, IEnumerator
{
// 成員變量
private ReversibleSortedList<TKey, TValue> _ReversibleSortedList;
private TValue currentValue;
private int index;
private int version;
internal ReversibleSortedListValueEnumerator(
ReversibleSortedList<TKey, TValue> ReversibleSortedList)
{
this._ReversibleSortedList = ReversibleSortedList;
this.version = ReversibleSortedList.version;
}
public void Dispose()
{
this.index = 0;
this.currentValue = default(TValue);
}
public bool MoveNext()
{
if (this.version != this._ReversibleSortedList.version)
{
throw new InvalidOperationException(
"Enumeration failed version check");
}
if (this.index < this._ReversibleSortedList.Count)
{
this.currentValue = this._ReversibleSortedList.values[this.index];
this.index++;
return true;
}
this.index = this._ReversibleSortedList.Count + 1;
this.currentValue = default (TValue);
return false;
}
void IEnumerator.Reset()
{
if (this.version != this._ReversibleSortedList.version)
{
throw new InvalidOperationException(
"Enumeration failed version check");
}
this.index = 0;
this.currentValue = default(TValue);
}
// 屬性
public TValue Current
{
get
{
return this.currentValue;
}
}
object IEnumerator.Current
{
get
{
if ((this.index == 0) || (this.index ==
(this._ReversibleSortedList.Count + 1)))
{
throw new InvalidOperationException (
"Enumeration Operation could not occur");
}
return this.currentValue;
}
}
}
#endregion