c# - Is there any automatic way to sync values of objects -


ide: vs 2010, c# .net winforms

hi, having 3 objects obj1 obj2 , obj3, , obj1 values initiated , obj2 values initiated , want in obj3 final object contain values of both obj1 , obj2, see below examples: (the values merged if not null or 0.

aclass obj1 = new aclass(); obj1.value1 = 14; aclass obj2 = new aclass(); obj2.value2 = 15; //i want aclass obj3 = new aclass(); obj3 = obj1 + obj2;  // not available  //i want obj3.value1 = 14 , obj3.value2 = 15 (initiated) 

is there faster or predefined way doing this.

no, there's no built in support merging... , unless types of value1 , value2 int?, may not able tell difference between "not initialized" , "initialized 0". (if they're properties, give them custom setters , remember properties have been set way.)

rather using +, suggest create own static method return merged instance:

aclass obj3 = aclass.merge(obj1, obj2); 

you'd need write logic within method, of course. can't give sample code without knowing more requirements , types.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -