How to remove duplicate values from int array in C#

1 Answer

0 votes
using System;
using System.Linq;
  
class Program
{
    static void Main() {
        int[] arr = { 5, 6, 1, 4, 1, 5, 5, 7 };
        
        arr = arr.Distinct().ToArray();
          
        foreach (int n in arr) {           
            Console.WriteLine(n);
        }
    }
}
  
  
  
/*
run:
  
5
6
1
4
7
  
*/

 



answered Nov 2, 2020 by avibootz

Related questions

1 answer 153 views
1 answer 168 views
1 answer 221 views
2 answers 165 views
1 answer 165 views
1 answer 109 views
...