I want to use 2 threads inside the foreach C #

0

I do not have much experience in C #. But I'm trying to understand the code of a program I have here.

Here use the following code:

foreach(var item in _main.entrada) {
....
}

I want to include the _main.said (along with the entry) in the foreach .... how can I do this?

    
asked by anonymous 18.05.2018 / 01:23

1 answer

0
  

I want to include the _main.session (along with the entry) in foreach .... how can I do this?

Yes, just use the Union method (it is in the System.Linq namespace) as long as the two collections are of the same type

foreach (var item in _main.entrada.Union(_main.saida))
{
    ...
}

Complete example:

public class MainCollection
{
    public int[] entrada;

    public int[] saida;

    public MainCollection()
    {
        entrada = new int[] { 1, 2, 3 };
        saida = new int[] { 4, 5, 6 };
    }
}


public class Program
{
    private static MainCollection _main = new MainCollection();

    public static void Main()
    {
        foreach (var item in _main.entrada.Union(_main.saida))
        {
            Console.WriteLine(item);
        }

        Console.ReadKey();

        return;
    }
}
    
18.05.2018 / 13:44