C# Program to return the difference between two sequences



Set two sequences.

double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 }; double[] arr2 = { 15.6, 30.5, 50.2 };

To get the difference between both the above arrays, use Except() method.

IEnumerable<double> res = arr1.AsQueryable().Except(arr2);

The following is the complete code.

Example

 Live Demo

using System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 };       double[] arr2 = { 15.6, 30.5, 50.2 };       Console.WriteLine("Initial List...");       foreach(double ele in arr1) {          Console.WriteLine(ele);       }       IEnumerable<double> res = arr1.AsQueryable().Except(arr2);       Console.WriteLine("New List...");       foreach (double a in res) {          Console.WriteLine(a);       }    } }

Output

Initial List... 10.2 15.6 23.3 30.5 50.2 New List... 10.2 23.3
Updated on: 2020-06-23T08:34:54+05:30

252 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements