Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Created November 6, 2023 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulsahay19/ac151ec93e31ccc024d5652bb91d45e8 to your computer and use it in GitHub Desktop.
Save rahulsahay19/ac151ec93e31ccc024d5652bb91d45e8 to your computer and use it in GitHub Desktop.
ParallelForEachExample
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class ParallelForEachExample
{
public static void Main(string[] args)
{
List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double sumSquares = 0.0;
Parallel.ForEach(numbers, number =>
{
double square = Math.Pow(number, 2);
sumSquares += square;
});
Console.WriteLine("Sum of squares: " + sumSquares);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment