下面的代码线程安全吗?
var dict = new Dictionary<int, string>()
{ { 0, "" }, { 1, "" }, { 2, "" }, { 3, "" } };
var nums = dict.Keys.ToList();
Parallel.ForEach(nums, num =>
{
dict[num] = LongTaskToGenerateString();
});
return dict;