【问题标题】:How to implement IEnumerable<T> on nested Dictionary?如何在嵌套字典上实现 IEnumerable<T>?
【发布时间】:2016-05-22 15:01:27
【问题描述】:

我有这门课:

public class MyClass<T> : IEnumerable<T>
{
    private Dictionary<T, Dictionary<T, double>> data = new Dictionary<T, Dictionary<T, double>>();

    public IEnumerator<T> GetEnumerator()
    {
        //Return what???
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}

但是我该如何实现GetEnumerator

【问题讨论】:

    标签: c# dictionary ienumerable


    【解决方案1】:

    字典有Keys 类型T 的集合:

    public IEnumerator<T> GetEnumerator()
    {
        return data.Keys.GetEnumerator();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-12
      • 2012-07-03
      • 2014-12-20
      • 1970-01-01
      • 2014-12-04
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多