【发布时间】:2017-03-28 17:50:18
【问题描述】:
谁能帮助我快速处理大字典中的所有数据?我认为 foreach 循环是一种缓慢的方法。
Dictionary<string, Student> dict = new Dictionary<string Student>();
foreach(var key in dict.keys) {
//do something with key
}
【问题讨论】:
标签: dictionary
谁能帮助我快速处理大字典中的所有数据?我认为 foreach 循环是一种缓慢的方法。
Dictionary<string, Student> dict = new Dictionary<string Student>();
foreach(var key in dict.keys) {
//do something with key
}
【问题讨论】:
标签: dictionary
如果你真的在处理每一个项目,下面的内容将一次性为你提供键和值:
foreach (var kvp in dict)
{
// do something with kvp.Key?
// do something with kvp.Value?
}
如果异步操作会有所帮助,Parallel.ForEach 之类的工具可能是您需要的工具。
【讨论】: