Click here to Skip to main content
15,887,477 members
Home / Discussions / C#
   

C#

 
AnswerRe: When the finally code is executed? Pin
N a v a n e e t h30-Jun-09 20:54
N a v a n e e t h30-Jun-09 20:54 
AnswerRe: When the finally code is executed? Pin
Christian Graus30-Jun-09 21:37
protectorChristian Graus30-Jun-09 21:37 
GeneralRe: When the finally code is executed? Pin
dojohansen30-Jun-09 22:45
dojohansen30-Jun-09 22:45 
GeneralRe: When the finally code is executed? Pin
PIEBALDconsult1-Jul-09 5:20
mvePIEBALDconsult1-Jul-09 5:20 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 5:34
dojohansen1-Jul-09 5:34 
GeneralRe: When the finally code is executed? Pin
PIEBALDconsult1-Jul-09 11:17
mvePIEBALDconsult1-Jul-09 11:17 
AnswerRe: When the finally code is executed? Pin
musefan30-Jun-09 22:00
musefan30-Jun-09 22:00 
GeneralRe: When the finally code is executed? Pin
dojohansen30-Jun-09 22:54
dojohansen30-Jun-09 22:54 
The answer is in fact more subtle: The finally block executes before the method returns, but the return value is *evaluated* before the finally block runs. Because his code works with a value type (int) the increment he did in the finally is not reflected in the return value of the method - it's as if the compiler transformed return i; to int ret = i; i += 3; return ret;, executing the finally block after evaluating the return expression, but before returning. If it had been an object (reference type) and the finally modified the state of that object, the caller would "see" the changes made by the finally block. See my replies above if you want more details.
GeneralRe: When the finally code is executed? Pin
musefan30-Jun-09 23:08
musefan30-Jun-09 23:08 
GeneralRe: When the finally code is executed? Pin
dojohansen30-Jun-09 23:26
dojohansen30-Jun-09 23:26 
GeneralRe: When the finally code is executed? Pin
J4amieC30-Jun-09 23:45
J4amieC30-Jun-09 23:45 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 0:40
dojohansen1-Jul-09 0:40 
GeneralRe: When the finally code is executed? Pin
musefan1-Jul-09 0:55
musefan1-Jul-09 0:55 
GeneralRe: When the finally code is executed? Pin
musefan1-Jul-09 2:08
musefan1-Jul-09 2:08 
GeneralRe: When the finally code is executed? Pin
J4amieC1-Jul-09 2:12
J4amieC1-Jul-09 2:12 
GeneralRe: When the finally code is executed? Pin
musefan1-Jul-09 2:19
musefan1-Jul-09 2:19 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 5:44
dojohansen1-Jul-09 5:44 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 5:37
dojohansen1-Jul-09 5:37 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 5:59
dojohansen1-Jul-09 5:59 
AnswerRe: When the finally code is executed? Pin
dojohansen30-Jun-09 22:25
dojohansen30-Jun-09 22:25 
AnswerRe: When the finally code is executed? Pin
Fired.Fish.Gmail1-Jul-09 0:39
Fired.Fish.Gmail1-Jul-09 0:39 
GeneralRe: When the finally code is executed? Pin
dojohansen1-Jul-09 0:43
dojohansen1-Jul-09 0:43 
GeneralRe: When the finally code is executed? Pin
Fired.Fish.Gmail1-Jul-09 0:46
Fired.Fish.Gmail1-Jul-09 0:46 
QuestionTrouble with making multiple httpWebRequest "Get"'s to a webservice in a short time Pin
nineismine30-Jun-09 20:39
nineismine30-Jun-09 20:39 
AnswerRe: Trouble with making multiple httpWebRequest "Get"'s to a webservice in a short time Pin
Philip.F30-Jun-09 20:49
Philip.F30-Jun-09 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.