say have method works follows:
methoda() { while(some condition) { computation... if(something 1) { computation... if(some condition) { return result; } } else if(something 2) { computation... if(some other condition) { return result; } } } return something; }
this method can return in both of conditions in while loop, or after while loop.
now want other method, call methodb()
, activated before returning. can this:
methoda() { while(some condition) { computation... if(something 1) { ... if(some condition) { methodb(); return result1; } else if(something 2) { ... if(some condition) { methodb(); return result2; } } } } methodb(); return result3; }
but find ugly. there nicer way in c#?
does methodb
depend on internal-state of methoda
? if not, wrap methoda
, call methodb
after the original methoda
(now renamed originalmethoda
) returns:
methoda() { var result = originalmethoda(); methodb(); return result; } originalmethoda() { // original methoda goes here, without calls methodb }
Comments
Post a Comment