C# Program to return the difference between two sequences

CsharpProgrammingServer Side Programming

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
raja
Published on 14-Sep-2018 12:12:11
Advertisements