Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Linq Except Method
Get the difference between two arrays using the Except() method.
The following are the two arrays.
int[] arr = { 9, 12, 15, 20, 35, 40, 55, 67, 88, 92 };
int[] arr2 = { 20, 35 };
To get the difference, use Except() method that returns the first list, except the elements in the second list.
arr.AsQueryable().Except(arr2);
The following is the entire example.
Example
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
int[] arr = { 5, 10, 15, 20, 35, 40 };
int[] except = { 20, 35 };
Console.WriteLine("Initial List...");
foreach(int ele in arr)
Console.WriteLine(ele);
IEnumerable<int> res = arr.AsQueryable().Except(except);
Console.WriteLine("New List...");
foreach (int a in res)
Console.WriteLine(a);
}
}
Output
Initial List... 5 10 15 20 35 40 New List... 5 10 15 40
Advertisements
