Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I have two List I wanted to get difference of two list in 3rd list. my 1st list null able.

What I have tried:

List<long?> RateCardList = new List<long?>();
                List<long> categorylist = new List<long>();
C#



List<long?> ThirdList = new List<long?>();
ThirdList = RateCardList.Except(categorylist);


I am getting error in ThirdList
Posted
Updated 23-Aug-17 19:57pm
v2

1 solution

You get the error because your argument to Except has long values, as opposed to RateListCard, that holds long?s.

Do this:
C#
ThirdList = RateCardList.Except(categoryList.Select(x => new long?(x)));
.Select(x => new long?(x)) takes all elements, calls the code to make them long?s and returns a new IEnumerable<long?>, which you can validly pass to Except.
 
Share this answer
 
Comments
Richard Deeming 25-Aug-17 14:23pm    
It might be marginally simpler to use Cast instead of Select:
.Except(categoryList.Cast<long?>())

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900