// 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;
C#使用下标遍历Dictionary
最新推荐文章于 2024-11-02 21:23:26 发布