How to Get different items from 2 lists using Linq in c#

25 Apr 2014, 08:51 AM

Simple check in where clause if element does not exist in list2 then add it. See the code below

 var list1 = new List<string>(){"UK", "USA", "China", "PK", "USA", "DK"};

 var list2 = new List<string>(){"UK", "USA", "UK", "USSR", "USA", "DK" };

 var result = list1.Where(p => !list2.Any(p2 => p2 == p));

Related Contents

15 May 2014, 08:07 AM
C#, LINQ, List
15 May 2014, 07:54 AM
C#, LINQ, List
29 Apr 2014, 03:07 AM
C#, Generic
About
explains How to get different items from 2 lists using Linq in c#

Date Posted 25 Apr 2014, 08:31 AM
Author Brainy Solutions
Views 2,216
;