C#使用下标遍历Dictionary

// dic为字典
for (int index = 0; index < dic.Count; index++)
{
var item = dic.ElementAt(index);
var itemKey = item.Key;
var itemValue = item.Value;
}
如果dic没有ElementAt()方法,是因为ElementAt 是一个扩展方法在 System.Linq.Enumerable 中定义。 故using System.Linq;

发布了24 篇原创文章 · 获赞 2 · 访问量 5615

猜你喜欢

转载自blog.csdn.net/qq_36537768/article/details/104344401