请看下面的一句话:枚举器(enumerator)接口包括非泛型接口System.Collections.IEnumerator和泛型接口System.Collections.Generic.IEnumerator<T>的所有实例化。
是不是说如果我想实现枚举器接口,那么我写个类继承自IEnumerator或IEnumerator<T>接口,然后实例化了类后,就是实现了此接口呢?

解决方案 »

  1.   

    我的看法,不一定正确
    你是在类中实现接口,不是在实例化时实现接口,
    你的类继承自IEnumerator或IEnumerator <T>接口,那么你这个类中如果写了实现接口的方法,实例化时肯定是实现了接口,否则那只能是个虚方法
      

  2.   

    碰巧前两天刚写过这个接口 using System;
    using System.Collections;namespace Date.Util
    {
    /// <summary>
    /// DateUtil 的摘要说明。
    /// </summary>  
    public class Big_Film_Key : IDictionaryEnumerator
    {
    System.Collections.DictionaryEntry[] items ;
    Int32 index = -1; int _id;//主键,自增ID
    int _FilmId;//我方影片ID
    string _nFilmUrl;//影片点播地址
    string _nBody;//备注信息
    string _nSet;//当前状态,1已上线
    int _SiteID;//站点ID
    string _Start_Time;//上片时间
    string _End_Time;//撤片时间
    int _nChannel;//频道信息
    int _Power;//影片权重值 public int id//主键,自增ID
    {
    get { return _id; }
    set { _id = value; }
    }
    public int FilmId//我方影片ID
    {
    get { return _FilmId; }
    set { _FilmId = value; }
    }
    public string nFilmUrl//影片点播地址
    {
      get { return _nFilmUrl; }
    set { _nFilmUrl = value; }  
    }
    public string nBody//备注信息
    {
    get { return _nBody; }
    set { _nBody = value; }
    }
    public string nSet//当前状态,1已上线
    {
    get { return _nSet; }
    set { _nSet = value; }
    }
    public int SiteID//站点ID
    {
    get { return _SiteID; }
    set { _SiteID = value; }
    }
    public string Start_Time//上片时间
    {
    get { return _Start_Time; }
    set { _Start_Time = value; }
    } public string End_Time//撤片时间
    {
    get { return _End_Time; }
    set { _End_Time = value; }
    }
    public int nChannel//频道信息
    {
    get { return _nChannel; }
    set { _nChannel = value; }
    }
    public int Power//影片权重值
    {
    get { return _Power; }
    set { _Power = value; }
    } /// <summary>
    /// 所有相关字段
    /// </summary>
    /// <returns></returns>
    private DictionaryEntry[] ItemList()
    {
    DictionaryEntry[] item = new DictionaryEntry[10];
    item[0].Key = "id";
    item[0].Value = id;
    item[1].Key = "FilmId";
    item[1].Value = FilmId;
    item[2].Key = "nFilmUrl";
    item[2].Value = nFilmUrl;  
    item[3].Key = "nBody";
    item[3].Value = nBody;
    item[4].Key = "nSet";
    item[4].Value = nSet;
    item[5].Key = "SiteID";
    item[5].Value = SiteID;
    item[6].Key = "Start_Time";
    item[6].Value = Start_Time;
    item[7].Key = "End_Time";
    item[7].Value = End_Time;
    item[8].Key = "nChannel";
    item[8].Value = nChannel;
    item[9].Key = "Power";
    item[9].Value = Power;
    return item;
    } #region IDictionaryEnumerator 成员
    public object Key
    {
    get { ValidateIndex();  return items[index].Key; }
    } public object Value
    {
    get { ValidateIndex();  return items[index].Value; }
    }   public System.Collections.DictionaryEntry Entry
    {
    get { return (DictionaryEntry) Current; }
    }
    #endregion #region IEnumerator 成员
    public void Reset()
    {
    index = -1;
    } public object Current
    {
    get { ValidateIndex(); return items[index]; } 
    } public bool MoveNext()
    {
    if (index < items.Length - 1) { index++; return true; }
    return false;
    }
    #endregion
    public Big_Film_Key()
    {
    //null
    } public Big_Film_Key(Big_Film_Key bfk)
    {
    items = new DictionaryEntry[bfk.Count];
    Array.Copy(bfk.ItemList(), 0, items, 0, bfk.Count);
    } private void ValidateIndex()
    {
    if (index < 0 || index >= items.Length)
    throw new InvalidOperationException("上下标越界!.");
    } #region 枚举Big_Film_Key表所有相关字段
    /// <summary>
    /// 枚举CopyRight表所有相关字段
    /// </summary>
    /// <returns></returns>
    public System.Collections.IDictionaryEnumerator GetEnumerator()
    {
    return new Big_Film_Key(this);
    }
    #endregion public int Count { get { return ItemList().Length; } } }  
    }
      

  3.   

    概念的问题
    所谓实现接口,接口只是一种功能的代名词,比如鸟和飞,鸟会飞,鸟类实现了飞这个接口
    bird : IFlyable当具体实例化后,代表了一个对象,一个实实在在的鸟bird b = new bird; 那么b当然也会飞