Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get distinct values from an array in C#? [duplicate]

Tags:

c#

Possible Duplicate:
Remove duplicates from array

How to get distinct values from an array in C#

like image 740
AK Jani Avatar asked Jan 11 '12 08:01

AK Jani


People also ask

How do you find a distinct number?

You can find the distinct values in an array using the Distinct function. The Distinct function takes the array as an input parameter and returns another array that consists only of the unique, or non-duplicate, elements.


2 Answers

You could use the .Distinct() extension method.

var collectionWithDistinctElements = oldArray.Distinct().ToArray();
like image 162
Darin Dimitrov Avatar answered Oct 07 '22 19:10

Darin Dimitrov


Using Distinct() function:

var distinctArray = myArray.Distinct().ToArray();
like image 23
Samich Avatar answered Oct 07 '22 19:10

Samich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!