C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Result: Here Except() returns a collection where the second array's elements are subtracted from the first.
Not found: No errors occur when Except() is called and some of the elements in the second collection are not found in the first collection.
And: The elements are ignored in the computation. Except() is not useful for validating that one collection is contained within another.
C# program that calls Except method
using System;
using System.Linq;
class Program
{
static void Main()
{
// Contains four values.
int[] values1 = { 1, 2, 3, 4 };
// Contains three values (1 and 2 also found in values1).
int[] values2 = { 1, 2, 5 };
// Remove all values2 from values1.
var result = values1.Except(values2);
// Show.
foreach (var element in result)
{
Console.WriteLine(element);
}
}
}
Output
3
4
And: It takes more code, and is not as impressive to read, but may be easier for other developers to understand it.