In VB.NET on a boolean function if you run an Exit Function line will it return false?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is correct, with the caveat that in VB the function name can also be a variable that is returned. If you’ve previously set that to true, it will return true.
More completely, in VB.Net, if I have a boolean function
Foo()defined like so:…the body of that function has an implied variable also named
Foothat matches the return type of the function —Booleanin this case, butObjectif the return type is omitted (you should be usingOption Strict, which requires a return type). This implied variable is initialized to use the default value for that type.If you fail to
Returna value from the function, whether viaExit Functionor simply by reaching the end, this implied variable is returned instead. Therefore, aBooleanfunction will returnFalseif youExit Functionearly without making other changes, because that is the default value in the implied variable used with the function. But you could also set that variable toTruefirst if you wanted, and thenExit Functionwould cause it to returnTrueinstead.These days people don’t often use the implied variable, but there are situations where it can save you a few lines of code without costing anything in clarity.