Click here to Skip to main content
15,908,274 members
Home / Discussions / C#
   

C#

 
AnswerRe: Comparing 2 lists Pin
Wayne Gaylard8-Sep-11 4:08
professionalWayne Gaylard8-Sep-11 4:08 
Just use a First query on the end of your Where query like this

C#
foreach(var p in list1.Count()>list2.Count() ? list2:list1 )
             {
                 var u=list2.Where(x => x.ID == p.ID || x.Empname == p.Empname ).FirstOrDefault();
             }


and that will return the first such emp. I use FirstOrDefault() in case there are no matches it will return a null Emp instead of throwing an Exception if there are no matches.

You need to look out if List2 is longer than List1 as you will then be matching List2 to List2 here list2.Where.

Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

AnswerRe: Comparing 2 lists Pin
Daniel.Grondal8-Sep-11 21:46
Daniel.Grondal8-Sep-11 21:46 
QuestionUploading already use file Pin
sarang_k8-Sep-11 1:34
sarang_k8-Sep-11 1:34 
AnswerRe: Uploading already use file Pin
BobJanova8-Sep-11 1:49
BobJanova8-Sep-11 1:49 
GeneralRe: Uploading already use file Pin
sarang_k8-Sep-11 2:11
sarang_k8-Sep-11 2:11 
GeneralRe: Uploading already use file Pin
MicroVirus8-Sep-11 5:00
MicroVirus8-Sep-11 5:00 
GeneralRe: Uploading already use file Pin
BobJanova8-Sep-11 6:12
BobJanova8-Sep-11 6:12 
GeneralRe: Uploading already use file Pin
Eddy Vluggen8-Sep-11 6:53
professionalEddy Vluggen8-Sep-11 6:53 
GeneralRe: Uploading already use file Pin
BobJanova8-Sep-11 10:25
BobJanova8-Sep-11 10:25 
GeneralRe: Uploading already use file Pin
Eddy Vluggen8-Sep-11 10:34
professionalEddy Vluggen8-Sep-11 10:34 
GeneralRe: Uploading already use file Pin
MicroVirus8-Sep-11 13:07
MicroVirus8-Sep-11 13:07 
QuestionDirectShowNET Framework 4.0 and 2.0 Pin
semixor8-Sep-11 1:10
semixor8-Sep-11 1:10 
AnswerRe: DirectShowNET Framework 4.0 and 2.0 Pin
Eddy Vluggen8-Sep-11 7:00
professionalEddy Vluggen8-Sep-11 7:00 
GeneralRe: DirectShowNET Framework 4.0 and 2.0 Pin
semixor8-Sep-11 9:01
semixor8-Sep-11 9:01 
AnswerRe: DirectShowNET Framework 4.0 and 2.0 Pin
Eddy Vluggen8-Sep-11 9:11
professionalEddy Vluggen8-Sep-11 9:11 
QuestionIBasicVideo + NullRenderer ( How ? ) Pin
semixor8-Sep-11 0:50
semixor8-Sep-11 0:50 
AnswerRe: IBasicVideo + NullRenderer ( How ? ) Pin
MicroVirus8-Sep-11 4:49
MicroVirus8-Sep-11 4:49 
GeneralRe: IBasicVideo + NullRenderer ( How ? ) Pin
semixor8-Sep-11 5:52
semixor8-Sep-11 5:52 
GeneralRe: IBasicVideo + NullRenderer ( How ? ) Pin
MicroVirus8-Sep-11 13:28
MicroVirus8-Sep-11 13:28 
GeneralRe: IBasicVideo + NullRenderer ( How ? ) Pin
semixor9-Sep-11 3:20
semixor9-Sep-11 3:20 
QuestionDeep Linking between views when using PRISM Pin
Phillip Donegan7-Sep-11 21:46
Phillip Donegan7-Sep-11 21:46 
QuestionEF Repository Questions Pin
Matt U.7-Sep-11 11:00
Matt U.7-Sep-11 11:00 
GeneralRe: EF Repository Questions Pin
PIEBALDconsult7-Sep-11 18:10
mvePIEBALDconsult7-Sep-11 18:10 
GeneralRe: EF Repository Questions Pin
Matt U.8-Sep-11 2:35
Matt U.8-Sep-11 2:35 
GeneralRe: EF Repository Questions Pin
PIEBALDconsult8-Sep-11 3:10
mvePIEBALDconsult8-Sep-11 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.