Now, I found this to be very interesting.. myObject was an instance of an object that clearly didn't implement IDisposable. Performing a cast like this would actually result in a null reference. The compiler was happy, the cast was invalid, and it ran without any problems at all.
I took a peek at the IL generated, and was pleasantly surprised to see that there is a check for nulls before the call to dispose.
I'm not sure if there is any benefit from doing this, and I'm sure I wont be recommending this to anybody, I just thought I'd mention it as an interesting tidbit.
Cheers
No comments:
Post a Comment