G
Guest
Hi,
What are the rules regarding ref parameters and interface types?
The reason I ask is that I found myself writing code like this several times:
if (something != null)
{
something.Dispose();
something = null;
}
So I had the "clever" idea of writing a routine like this:
public static void MyDispose(IDisposable disposable)
{
if (disposable != null)
{
disposable.Dispose();
disposable = null;
}
}
I can pass variables of type IDisposable to this routine, but I cannot pass class types that implement IDisposable. E.g. I wanted to do something like:
Bitmap MyBitmap = ....
.....
MyDispose(MyBitmap);
It seems to me that the compiler should be able to figure out what I want (i.e. pass my bitmap to the method, just like it does if its not a ref parameter) then set MyBitmap to null. The compiler disagrees with this plan, and gives an error.
Is there any way to ahieve what I want?
JR
What are the rules regarding ref parameters and interface types?
The reason I ask is that I found myself writing code like this several times:
if (something != null)
{
something.Dispose();
something = null;
}
So I had the "clever" idea of writing a routine like this:
public static void MyDispose(IDisposable disposable)
{
if (disposable != null)
{
disposable.Dispose();
disposable = null;
}
}
I can pass variables of type IDisposable to this routine, but I cannot pass class types that implement IDisposable. E.g. I wanted to do something like:
Bitmap MyBitmap = ....
.....
MyDispose(MyBitmap);
It seems to me that the compiler should be able to figure out what I want (i.e. pass my bitmap to the method, just like it does if its not a ref parameter) then set MyBitmap to null. The compiler disagrees with this plan, and gives an error.
Is there any way to ahieve what I want?
JR