c# - Passing an IDisposable object by reference causes an error? -
I am trying to create a common method for disposal of an object, named DisposeObject ( )
To ensure that I am disposing of objects indicated by a parent reference, I am trying to pass an object from context.
But I got a compilation error
The 'riff' argument type does not match the parameter type
Below (simplified) code In, apply both _Baz and _Bar .
You do not need to pass the context, because you are passing a reference type. You should remove the ref keyword from your method definition and do this and you should not have any problem, although I'm not sure whether this is simply more effective or obvious than simply Dispose ( (It is different from the fact that you do not need to insert it for a clear implementation and it checks for a null for you.)
< Strong> edit
dance, while I hope to discuss which Surrounded by topic, he proved to be useful for you, your original intention does not seem like something that Snbvniy. To pass something as referee , you can not pass a variable that is different than the ref parameter (in other words, you can not pass A variable declared as a class or other interface which implements IDisposable if ref parameter IDisposable ). Because the ref parameter allows to collar back to the caller, you will open the possibility of storing incompatible types in your variable.
Here is your best bet to assign blank if you want what you want if you want to check out null and on that function Exceptions that want to ignore are ok, but in this scenario ref will not work for you, yet unfortunately.
Comments
Post a Comment