I have C# .NET 4 code which is adding to a List<string>
inside a Parallel.For
.
I can't find a definite answer to if this is thread-safe or not.
If it is unsafe what are the alternatives?
static List<int> Calculate(List<string[]> numbers)
{
List<int> sums = new List<int>();
Parallel.ForEach(numbers,
(nums) =>
{
int sum = 0;
for (int i = 0; i < nums.Length; i++)
sum += Convert.ToInt32( nums[i]);
// is this thread safe or not???
sums.Add(sum);
});
sums.Sort();
return sums;
}