Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Prog20180921
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Дано масив цілих чисел. Подвоїти парні і потроїти непарні значення.
- int[] arr1 = new[] { 1, 2, 3, 4, 5 };
- int[] res1 = OneThread(arr1);
- int[] res2 = ParallelThread(arr1);
- }
- private static int[] ParallelThread(int[] arr)
- {
- int[] res = new int[arr.Length];
- Parallel.For(0, arr.Length, (i) =>
- {
- if (arr[i] % 2 == 0)
- {
- res[i] = arr[i] * 2;
- }
- else
- {
- res[i] = arr[i] * 3;
- }
- });
- return res;
- }
- private static int[] OneThread(int[] arr)
- {
- int[] res = new int[arr.Length];
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 == 0)
- {
- res[i] = arr[i] * 2;
- }
- else
- {
- res[i] = arr[i] * 3;
- }
- }
- return res;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement