Sunday, 15 July 2012

c# - Dictionary merging without duplicate? -



c# - Dictionary<enum,class> merging without duplicate? -

i have struggled find logic con-cat or merge 2 dics ..

enum type { first, second, 3rd } class sample { string name; int no; } public static dictionary<type,list<sample>> getdatadir(dictionary<type,list<sample>> data1,dictionary<type,list<sample>> data2) { dictionary<type,list<sample>> dataout = new dictionary<type,list<sample>>(); // here 1 of sample instance (data1) , key name equal status ,we have update data1 dic key , update sample of data2 homecoming dataout ; }

please help me find way come out ...

i think after.

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapplication3 { internal enum sampleenum { a, b, c, d } internal class programme { private static void main(string[] args) { var = new dictionary<sampleenum, samplevalue>(); var b = new dictionary<sampleenum, samplevalue>(); a.add(sampleenum.a, new samplevalue()); a.add(sampleenum.b, new samplevalue()); b.add(sampleenum.a, new samplevalue()); b.add(sampleenum.b, new samplevalue()); b.add(sampleenum.c, new samplevalue()); b.add(sampleenum.d, new samplevalue()); // add together missing b values foreach (var objitem in l2 in b !a.containskey(l2.key) select l2) { a.add(objitem.key, objitem.value); } // merge b's values foreach (var objitem in l2 in b a.containskey(l2.key) select l2) { a[objitem.key] = objitem.value; } system.diagnostics.debug.assert(true); } } internal class samplevalue { } }

c# dictionary

No comments:

Post a Comment