I would like to know whether my use of using
is correct. In the using
statmement, I am deciding whether or not the image should be used in the game.
Image imageOfEnemy;
using(imageOfEnemy=Bitmap.FromFile(path))
{
// some stuff with the imageOfEnemy variable
}
From my understanding, I do not need to call Dispose
now.
using is a shorthand statement for IDisposable objects to simplify the try-finally block, with Dispose in the finally block.
http://msdn.microsoft.com/en-us/library/yh598w02.aspx
So yes, you don't have to call Dispose 'manually' in this case.
the Main method will be this in MSIL:
You can see the try-finally handler and the Dispose call even if you are new to MSIL.