我是一名C#愛好者,我正在使用Parallel.ForEach方法。我嘗試使用下面的代碼顯示給定的系統環境變量:如何使用Parallel.ForEach顯示IDictionary的值?
IDictionary vars = Environment.GetEnvironmentVariables();
Parallel.ForEach(vars, (envVar) =>
{
Console.WriteLine("{0} = {1}", envVar.Key, envVar.Value);
});
但是我結束了這個錯誤:
Error 3 The type arguments for method 'System.Threading.Tasks.Parallel.ForEach<TSource>(System.Collections.Concurrent.OrderablePartitioner<TSource>, System.Action<TSource,System.Threading.Tasks.ParallelLoopState,long>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
我敢肯定,我缺少強制但無論我試過我無法使它工作。 你能幫我嗎?
只有具有泛型集合的作品。另外,這裏沒有理由使用並行性。 – SLaks