How to count the array elements only once in C#

1 Answer

0 votes
using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        int[] arr = {4, 1, 2, 8, 9, 5, 1, 7, 8, 8, 8};

        Console.WriteLine(arr.Distinct().Count());
    }
}
 
 
 
 
/*
run:
 
7
 
*/

 



answered Apr 18, 2022 by avibootz
...