Use Except to print numbers that are in one integer array, but not another : Except « LINQ « C# / C Sharp






Use Except to print numbers that are in one integer array, but not another

 

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);
        }
    }
}

 








Related examples in the same category

1.One array expect another array
2.Use Except to print the first character of product names that aren't also the first character of customer names.
3.Except Prototype