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

    


One array expect another array

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

public class MainClass{
   public static void Main(){
            int[] numbers = {1, 2, 3, 4};
            int[] numbers2 = {1, 1, 3, 3};
            Console.Write(numbers.Except(numbers2));
   }
}

    


Use static method syntax to call the query operators.

   
 

using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
    public static void Main() {
        string[] names = { "J", "P", "G", "Pa" };

        IEnumerable<string> filtered = Enumerable.Where(names,n => n.Contains("a"));
        IEnumerable<string> sorted = Enumerable.OrderBy(filtered, n => n.Length);
        IEnumerable<string> finalQuery = Enumerable.Select(sorted,n => n.ToUpper());

    }
}

    


Calling the Range Operator

   
 

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

public class MainClass {
    public static void Main() {
        IEnumerable<int> ints = Enumerable.Range(1, 10);
        foreach (int i in ints)
            Console.WriteLine(i);
    }
}