asp.net - Merge two object lists in C# with LINQ -
i have 2 list<t>s both same type. there easy way merge 2 sets without looping though both sets , merging them third?
code
var myobject= new list<core.myobject>(); var myobject2= new list<core.myobject>(); if(!string.isnullorempty(txb.text)) { var repository = servicelocator.current.getinstance<core.repositoryinterfaces.irepository>(); myobject= repository.getwherepostcodelike(txb.text).tolist(); } if(!string.isnullorwhitespace(ddl.selectedvalue)) { var repository = servicelocator.current.getinstance<core.repositoryinterfaces.irepository>(); myobject2= repository.getneartownx(ddllocations.selectedvalue).tolist(); } it have been nice able able use += on second, not allowed... ideas?
call concat (keeps duplicates) or union (skips duplicates) linq methods
ienumerable<myobject> third = list.concat(otherlist); to use union, you'll need override equals , gethashcode compare objects value. (or pass iequalitycomparer<myobject>)
Comments
Post a Comment