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 150 views
1 answer 71 views
2 answers 156 views
156 views asked Mar 19, 2023 by avibootz
1 answer 193 views
2 answers 267 views
1 answer 177 views
...