gpt4 book ai didi

c# - 如何在嵌套字典上实现 IEnumerable

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:25 26 4
gpt4 key购买 nike

我有这门课:

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

最佳答案

字典有 Keys 类型 T 的集合:

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

关于c# - 如何在嵌套字典上实现 IEnumerable<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37375925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com