- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
Advertisements