我正在尝试找出一种方法来报告使用以下代码循环遍历字典的进度:
int progressTracker = 0;
foreach (KeyValuePair<string, Func<T>> methodPair in DicitionaryCollection)
{
progressTracker++;
progressTracker = (100 * progressTracker) / DicitionaryCollection.Count;
// do something with progress and collection contents
}
然而,这会不断返回值,在值方面有点跳跃。有什么想法吗?
最佳答案
使用不同的变量。
int currentProgress= 0;
foreach (KeyValuePair<string, Func<T>> methodPair in DicitionaryCollection)
{
currentProgress++;
int progressTracker = (100 * currentProgress) / DicitionaryCollection.Count;
// do something with progress and collection contents
}
关于c# - 根据字典集合大小增加进度指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20166417/