Created
November 6, 2023 16:16
-
-
Save rahulsahay19/ac151ec93e31ccc024d5652bb91d45e8 to your computer and use it in GitHub Desktop.
ParallelForEachExample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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