I’m not sure if my title is really correct. I’ve looked around and searched but not found anything so please forgive me if my problem has been answered already.
What I would like to do is call a function but not have to come back to the calling line of code. e.g
public static void temp(obj) {
switch (obj.id) {
case "1" :
if(blah) {
obj.id = "2";
temp(obj);
}
break;
case "2" :
obj.response = "done";
break;
}
}
so basically I dont want to eventually come back to my temp(obj) in the first case and fully pass control. Does this make sense, is it even possible and my architecture is all wrong?
Thank you for your time.
Let me see if I understand the question:
You’ve got a function
Foo(), which calls functionBar(). (I wanted to remove the recursion you had in your example for simplicity, please correct me if that was important.) When functionBar()returns, you want control to pass not back toFoo(), but to Foo’s caller?This is probably possible in lower-level languages, like C, by hacking the stack and not placing
Foo()‘s return address there, so that whenBar()tried to return, it would jump to Foo’s caller instead.However, in C#, no. The call stack is a stack, and control will pass back in order. The only thing you can do would be to put a
returnstatement after each call toBar().Edit:
“recursive calls without them being recursive”
How about this: