Say I have a method A that works something as follows:
methodA() {
while(some condition) {
do computation...
if(something 1) {
do computation...
if(some condition) {
return result;
}
}
else if(something 2) {
do computation...
if(some other condition) {
return result;
}
}
}
return something;
}
This method can return in both of the conditions in the while loop, or after the while loop.
Now say I want some other method, call it methodB()
, to be activated before returning. I can do something like this:
methodA() {
while(some condition) {
do computation...
if(something 1) {
...
if(some condition) {
methodB();
return result1;
}
else if(something 2) {
...
if(some condition) {
methodB();
return result2;
}
}
}
}
methodB();
return result3;
}
But I find it ugly. Is there a nicer way to do something like that in C#?