LINQ Query To Count Unique Numbers In An Array

Akiii
Posted by Akiii under LINQ category on | Points: 40 | Views : 4615
Hi all,

Here, i will show how to use LINQ query to count unique numbers in an array :-

Suppose, we have an integer array:-

int[] myarray = { 1, 1, 2, 2, 3, 3 };

Now, i will use LINQ query:-

int numbers = myarray.Distinct().Count();

Thus, printing the value:-

Response.write("There are {0} unique numbers", numbers);

Output:-

There are 3 unique numbers



Please, feel free to let me know if there is any error.
Thanks and Regards
Akiii

Comments or Responses

Login to post response