Click here to Skip to main content
14,356,770 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need to compare two list (GroupName,FieldName,Sequence) values and get the difference & same values in list...
I have tried some linq C# but not get correct data.


CompareTwoList | C# Online Compiler | .NET Fiddle[^]

plz help

What I have tried:

var Matches = lstS.Where(y => lstT.Any(z => z.GroupName == y.GroupName)).ToList();
               var MatchesBoth = lstS.Where(y => lstT.Any(z => z.GroupName == y.GroupName && z.FieldName == y.FieldName)).ToList();
               var SourceDiffer = lstS.Where(x => !lstT.Any(z => z.GroupName == x.GroupName && z.FieldName == x.FieldName)).ToList();
               var TargetDiffer = lstT.Where(x => !lstS.Any(z => z.GroupName == x.GroupName && z.FieldName == x.FieldName)).ToList();
Posted
Updated 17-Sep-19 7:08am
Comments
Maciej Los 17-Sep-19 9:36am
   
What kind of result do you expect?
venkatesh (chennai) 17-Sep-19 9:48am
   
Source G1 A 1 IsDiffer
Target G1 A 2 IsDiffer

Source G1 B 2 IsDiffer
Target G1 B 3 IsDiffer

Source - - - IsDiffer
Target G1 C 1 IsDiffer

Source G2 C 1 IsDiffer
Target - - - IsDiffer

Source G3 D 1 IsDiffer
Target - - - IsDiffer

Source G3 E 1 IsDiffer
Target - - - IsDiffer

Source G2 D 1 IsDiffer
Target - - - IsDiffer

Source - - - IsDiffer
Target G2 E 2 IsDiffer

Source G4 E 2 Match
Target G4 E 2 Match

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Use "Set" operations.

Set Operations (C#) | Microsoft Docs[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100