Problem
I am trying to return a unique element from a C# array with the in-built method array.Distinct.First(). The method works for some arrays but returns an incorrect element for this array {11,11,11,14,11,11}. It gives me an output of 11 which is incorrect because the unique element in that array is supposed to 14.
I know there is a way to do that with a predicate function but that is just the reason why am asking, I do not know
Code
public static int getUnique(IEnumerable<int> numbers){
return numbers.Distinct().First();
//you can bet i tried .FirstOrDefault()
//without any success
}
Any help to make that code return the correct value is highly appreciated.
{11,11,11,14,11,12}, etc?array.GroupBy(x => x).Where(x =>x.Count() == 1).First()