程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 構建可反轉排序的泛型字典類(6)--實現IDictionary接口中的Keys和Values屬性(3)

構建可反轉排序的泛型字典類(6)--實現IDictionary接口中的Keys和Values屬性(3)

編輯:關於C語言

同理,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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved