Click here to Skip to main content
15,905,967 members
Home / Discussions / C#
   

C#

 
AnswerRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
Manas Bhardwaj30-Jun-09 22:13
professionalManas Bhardwaj30-Jun-09 22:13 
GeneralRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
devvvy1-Jul-09 1:14
devvvy1-Jul-09 1:14 
AnswerRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
Manas Bhardwaj1-Jul-09 1:41
professionalManas Bhardwaj1-Jul-09 1:41 
GeneralRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
devvvy1-Jul-09 1:41
devvvy1-Jul-09 1:41 
GeneralRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
Manas Bhardwaj1-Jul-09 1:46
professionalManas Bhardwaj1-Jul-09 1:46 
GeneralRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." Pin
devvvy1-Jul-09 1:49
devvvy1-Jul-09 1:49 
AnswerRe: "Cannot access a disposed object.\r\nObject name: 'Transaction'." [modified] Pin
RussVB25-Aug-09 16:38
RussVB25-Aug-09 16:38 
QuestionCancel Events Pin
satsumatable30-Jun-09 21:56
satsumatable30-Jun-09 21:56 
AnswerRe: Cancel Events Pin
DaveyM6930-Jun-09 22:06
professionalDaveyM6930-Jun-09 22:06 
GeneralRe: Cancel Events Pin
satsumatable30-Jun-09 22:34
satsumatable30-Jun-09 22:34 
GeneralRe: Cancel Events Pin
Cracked-Down30-Jun-09 22:58
Cracked-Down30-Jun-09 22:58 
QuestionRe: Cancel Events Pin
musefan1-Jul-09 1:21
musefan1-Jul-09 1:21 
QuestionHow to attach file when sending emails Pin
dabuskol30-Jun-09 21:54
dabuskol30-Jun-09 21:54 
AnswerRe: How to attach file when sending emails Pin
Manas Bhardwaj30-Jun-09 21:58
professionalManas Bhardwaj30-Jun-09 21:58 
QuestionHow to close the form using Alt+f4? Pin
swetha_insoft30-Jun-09 21:37
swetha_insoft30-Jun-09 21:37 
AnswerRe: How to close the form using Alt+f4? Pin
SeMartens30-Jun-09 21:41
SeMartens30-Jun-09 21:41 
AnswerRe: How to close the form using Alt+f4? Pin
stancrm30-Jun-09 21:41
stancrm30-Jun-09 21:41 
AnswerRe: How to close the form using Alt+f4? Pin
DaveyM6930-Jun-09 22:24
professionalDaveyM6930-Jun-09 22:24 
QuestionWhen the finally code is executed? Pin
Fired.Fish.Gmail30-Jun-09 20:45
Fired.Fish.Gmail30-Jun-09 20:45 
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 
Well that is a dumb answer because it's totally unhelpful!

You're right that it won't compile, but surely you can see that the question works by simply declaring i at the method level instead. And there is in fact a subtle effect of the try-finally.

int foo()
{
  int i = 1;
  try { return i; }
  finally { i = 5; }
}


This code compiles, but what does foo() return? I think quite a lot of people would expect it to return 5, since the finally block is executed before the method returns. But the return value is *evaluated* before the finally block runs and the method returns 1.

Now what would happen if we boxed the int in a class of our own?

class BoxedInt { public int Value; }

BoxedInt bar()
{
  BoxedInt i = new BoxedInt() { Value = 1 };
  try { return i; }
  finally { i.Value = 5; }
}


While foo() returns 1, bar() returns a BoxedInt whose Value is 5. That's because BoxedInt is a class and thus a reference type, so it does not matter if the return value is evaluated before or after the finally block executes. Change BoxedInt to a struct, and bar will return a BoxedInt with Value equal to 1 as well.

I'd say there's some subtlety here, so calling that a stupid question seems to me rather a stretch.
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 

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.