How to remove all duplicate elements from int array in C#

1 Answer

0 votes
using System;
using System.Linq;

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

            var distinct_arr = arr.Distinct();

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


/*
run:
     
1
2
3
4
5
6
 
*/

 



answered Feb 21, 2017 by avibootz
...