How is this exiting?
-
I'm asking this here because few coworkers can comprehend the notion of a theoretical question.
I don't understand how this is exiting the recursive loop, but yet it only goes through twice.
public override PVR VHP(string hP, string provPass) { string[] passProps = hP.Split('|'); if(passProps.Length != 3) { return base.VHP(hP, provPass); } else { //doesn't make it here } }
Any thoughts?
-
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
-
@hungrier said in How is this exiting?:
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
This. I would not expect it to ever call the posted code more than once at all.
-
It does not compile.
Since it has a return type ofVHP
, there must be something (ornull
) to retrun in each part of the if-else clause or at least afterwards.
-
@BernieTheBernie said in How is this exiting?:
It does not compile.
Since it has a return type ofVHP
, there must be something (ornull
) to retrun in each part of the if-else clause or at least afterwards.There's likely code that would return in the else section but isn't shown due to brevity in showing the apparent path.
-
@Tsaukpaetra said in How is this exiting?:
@hungrier said in How is this exiting?:
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
This. I would not expect it to ever call the posted code more than once at all.
Once here, once in the base method?
-
@Watson said in How is this exiting?:
@Tsaukpaetra said in How is this exiting?:
@hungrier said in How is this exiting?:
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
This. I would not expect it to ever call the posted code more than once at all.
Once here, once in the base method?
If the base method is completely duplicated in the overridden method, what is the point?
-
@jinpa said in How is this exiting?:
I'm asking this here because few coworkers can comprehend the notion of a theoretical question.
I don't understand how this is exiting the recursive loop, but yet it only goes through twice.
public override PVR VHP(string hP, string provPass) { string[] passProps = hP.Split('|'); if(passProps.Length != 3) { return base.VHP(hP, provPass); } else { //doesn't make it here } }
Any thoughts?
this is an override method.
base.VHP
is the reference to the base method that this one is overriding. looks like for some reason this override is filtering out hP strings that have exactly two vbars|
in them..... why? i dont' know. but that's what it's doing.you're not doing a recursive call here at all, just filtering then calling the base class's version of this method to do the actual work.
-
@Tsaukpaetra said in How is this exiting?:
@Watson said in How is this exiting?:
@Tsaukpaetra said in How is this exiting?:
@hungrier said in How is this exiting?:
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
This. I would not expect it to ever call the posted code more than once at all.
Once here, once in the base method?
If the base method is completely duplicated in the overridden method, what is the point?
just wondering what "goes through twice" might mean.
-
@Watson said in How is this exiting?:
@Tsaukpaetra said in How is this exiting?:
@Watson said in How is this exiting?:
@Tsaukpaetra said in How is this exiting?:
@hungrier said in How is this exiting?:
@jinpa Since it's an override method calling base, are you sure it's recursive at all?
This. I would not expect it to ever call the posted code more than once at all.
Once here, once in the base method?
If the base method is completely duplicated in the overridden method, what is the point?
just wondering what "goes through twice" might mean.
I believe the context is, it is intended to recursively call this same function with cut-out portions until the function is called with parameters that result in that passProps having three sections (separated by
|
) in the parameter hP, at which point it will call the base function.What isn't being shown here is what would make the function recursive (i.e. the
else
portion that munges the hP string and calls itself again).
-
@Watson said in How is this exiting?:
just wondering what "goes through twice" might mean.
Wild-ass guessing, but possibly:
this.VHP(hp, provPass); base.VHP(hp, provPass);
-
@hungrier So it turns out that, no, I'm not. There are multiple reasons why it appeared to me to be recursive, however. The primary ones are that right-clicking and Go to Implementation took me back to the method, and pressing F11, Step Into, took me back into the method. In my past experience, either of those would have given me an error message if it was unable to go directly to or decompile the code. MS fooled me again.
-
@jinpa said in How is this exiting?:
pressing F11, Step Into, took me back into the method
-
@Zecc said in How is this exiting?:
@jinpa said in How is this exiting?:
pressing F11, Step Into, took me back into the method
This happens more in optimized compilations IME when the debugger isn't actually sure what line of code you're on because several things are happening kinda-out-of-order.