Do Except on two int arrays in CSharp

Description

The following code shows how to do Except on two int arrays.

Example


   /*from w w  w . j a v  a2s.  c  om*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
        int[] numbersB = { 1, 3, 5, 7, 8 };

        IEnumerable<int> aOnlyNumbers = numbersA.Except(numbersB);

        Console.WriteLine("Numbers in first array but not second array:");
        foreach (var n in aOnlyNumbers) {
            Console.WriteLine(n);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ