0

a = 3 7 4 2 8 10
b = 8 3 7 4 2 8

result should 8

How can I achieve the above result while using LINQ? If it is not possible in LINQ then an alternative solution for this

var diff = b.Except(a);
2
  • Your a array has the value 8 as well, is that intended? Commented Jul 7, 2019 at 21:57
  • I want to get the value that is not present in a. Considering duplicates. Means once 8 is missing in a. diff should be equal to 8. @Ray Commented Jul 7, 2019 at 22:03

1 Answer 1

1
var a = new List<int>(){3 ,7 ,4 ,2 ,8 ,10};
var b =new List<int>() {8 ,3 ,7 ,4 ,2 ,8};
a.ForEach(n1=>b.Remove(n1));
b.ForEach(Console.WriteLine);     //8
Sign up to request clarification or add additional context in comments.

3 Comments

the diff was blank for the above query
so either it should return 10 or 8. Basically wants to find the missing one.
@akshay_zz for some reason I missed the considering duplicate part, that should do the trip, if you don't want to change the original b array, just use the CopyTo method, and generate a temp one to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.