Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

/ C# program to merge two array into a single

// array without duplicate elements

using System;

using System.Collections.Generic;

using System.Linq;

class GFG{

public static void Main()

// Declare first array with integer numbers

int[] array1 = { 1, 2, 3, 8, 100, 4, 65, 9, 7 };

// Declare second array with integer numbers

int[] array2 = { 5, 6, 43, 8, 39, 74, 9, 100 };

// Displaying array 1

Console.WriteLine("Array 1: ");

foreach (int x1 in array1)

Console.WriteLine(x1);

// Displaying array 2

Console.WriteLine("Array 2: ");
foreach (int x2 in array2)

Console.WriteLine(x2);

// Combine the unique elements and convert into array

var final = array1.Union(array2).ToArray();

// Display the elements in the final array

Console.WriteLine("New array:");

Array.ForEach(final, i => Console.WriteLine(i));

You might also like