How to computes mathematical unions (removes duplicates) on two int arrays in C#

2 Answers

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr1 = { 1, 2, 3, 4, 4, 5 };
            int[] arr2 = { 2, 3, 4, 6 };

            var unionArr = arr1.Union(arr2);

            foreach (int n in unionArr)
                Console.WriteLine(n);
        }
    }
}


/*
run:

1
2
3
4
5
6

*/

 



answered Feb 28, 2017 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] arr1 = { 'a', 'b', 'b', 'x', 'c' };
            char[] arr2 = { 'c', 'b', 'y' };

            var unionArr = arr1.Union(arr2);

            Console.WriteLine(string.Join(", ", unionArr));
        }
    }
}


/*
run:

a, b, x, c, y

*/

 



answered Feb 28, 2017 by avibootz

Related questions

3 answers 255 views
1 answer 111 views
3 answers 249 views
249 views asked Mar 14, 2017 by avibootz
2 answers 188 views
1 answer 208 views
2 answers 257 views
1 answer 141 views
...