Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
731 B
1
Indexable
Never
using System;
using System.Threading;

class Program {
    static void Main(string[] args) {
        int[] a = { 1, 2, 3 };
        int[] b = { 4, 5, 6 };
        int[] result = new int[3];
        Thread t1 = new Thread(() => SumArrays(a, b, result, 0, 1));
        Thread t2 = new Thread(() => SumArrays(a, b, result, 1, 2));
        t1.Start();
        t2.Start();
        t1.Join();
        t2.Join();
        Console.WriteLine("Result: " + string.Join(", ", result));
        Console.ReadLine();
    }

    static void SumArrays(int[] a, int[] b, int[] result, int startIndex, int endIndex) {
        for (int i = startIndex; i < endIndex; i++) {
            result[i] = a[i] + b[i];
        }
    }
}