Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n = 10;
- short []tab = new short[n];
- Random rand = new Random();
- Parallel.For(0, n, i =>
- {
- tab[i] = (short)rand.Next(0, 5);
- });
- long total = 0;
- Parallel.For<short>(0, n, () => 0, (j, loop, subtotal) =>
- {
- subtotal += tab[j];
- return subtotal;
- },
- (x) => Interlocked.Add(ref total, x)
- );
- Console.WriteLine("Suma {0}", total);
- Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement