Friday, 15 July 2011

c# - How to merge two lists while adding metadata indicating value source with LINQ statement? -



c# - How to merge two lists while adding metadata indicating value source with LINQ statement? -

given, instance:

var = new list<int>(){ 1 , 2 , 50 }; var b = new list<int>(){ 9 , 7 , 2 };

i need merge them 1 sorted list, while adding info indicating origin (a or b). output illustration like:

mergedlist = { {1,false},{2,false},{2,true},{7,true},{9,true},{50,false} }

(true means comes a).

edit start... mergedlist = { {1,isb=false},{2,isb=false},{2,isb=true},{7,isb=true},{9,isb=true},{50,isb=false} } ...edit end

how can linq, preferably in query statement form (from ... select ...) ?

var aitems = aa in select new {value = aa, indicator = true}; var bitems = bb in b select new {value = bb, indicator = false}; var result = aitems.concat(bitems).orderby(t => t.value);

and pure method syntax:

var aitems = a.select(aa => new {value = aa, indicator = true}); var bitems = b.select(bb => new {value = bb, indicator = false}); var result = aitems.concat(bitems).orderby(t => t.value);

c# linq c#-4.0

No comments:

Post a Comment