How to remove duplicates from int array in C#

1 Answer

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

 



answered Sep 22, 2020 by avibootz

Related questions

2 answers 161 views
1 answer 80 views
2 answers 169 views
169 views asked Mar 19, 2023 by avibootz
1 answer 200 views
2 answers 279 views
1 answer 183 views
...