Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now

Create Unique integer array in C# | check if array contains a duplicate number in C#

 

Create Unique array  in C# | check if array contains a duplicate number in C#


In this article we will see to create unique array.

C# Code

    public static void UniqueArrayElement()

        {

            int[] items = { 1, 4, 2, 5, 4, 2, 5, 1, 6, 2, 5, 3, 8, 9, 6 };

            int n = items.Length;

 

            Console.WriteLine("Unique array elements: ");

 

            for (int i = 0; i < n; i++)

            {

                bool isDuplicate = false;

                for (int j = 0; j < i; j++)

                {

                    if (items[i] == items[j])

                    {

                        isDuplicate = true;

                        //Console.WriteLine(items[i] + " is duplicated");

                        break;

                    }

                }

 

                if (!isDuplicate)

                {

                    Console.WriteLine(items[i]);

 

                }

            }

 

            Console.ReadLine();

        }


Output




Share this

Related Posts

Previous
Next Post »

Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now