Except
In this chapter you will learn:
Get to know Except operator
Except
returns the elements in the
first input sequence that are not present in the second:
using System;/*from ja va2s . c o m*/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] seq1 = { 1, 2, 3 };
int[] seq2 = { 3, 4, 5 };
IEnumerable<int> difference1 = seq1.Except(seq2);
IEnumerable<int> difference2 = seq2.Except(seq1);
foreach (int i in difference1)
{
Console.WriteLine(i);
}
foreach (int i in difference2)
{
Console.WriteLine(i);
}
}
}
The output:
Except with String array
using System;// ja v a 2 s. co m
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
public class MainClass{
public static void Main(string[] args){
String[] First = { "One", "Two", "Two", "Three", "Four" };
String[] Second = { "Three", "Four", "Five", "Six" };
var ShowExcept = First.Except(Second);
Console.WriteLine("Except:");
foreach (String ThisElement in ShowExcept)
Console.WriteLine(ThisElement);
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Linq Operators