We list. Besides the problem

Can someone explain why this does not work, as it seems to me.

double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.3, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };

IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2);

foreach (double number in onlyInFirstSet)
    Console.WriteLine(number);

/*
 This code produces the following output:

 2
 2.1
 2.3
 2.4
 2.5
*/

What I expect will be 2, 2.1, 2.3, 2.3, 2.3, 2.4, 2.5. Why not return the reporting list? This is mistake?

Update:

Well, I completely skipped this point in the docs. Funny 4 people respond with the same answer. You might think that you just ask the guy who answered him first. :)

+5
source share
3 answers

Why return a separate list? This is mistake?

Nope. Exceptcreates an established difference . See Documentation:

Makes the specified difference between the two sequences using the default comparison to compare values.

, , Where . :

"abcdddefffg".Where(e => !"cde".Contains(e));       // Produces "abfffg".
+8

. Except , IEnumerable. , . . MSDN.

+1

" " - "" , "" . , .

+1

All Articles