Everybody knows that using keyword is used when we want to clean up the unmanaged resources.
If the class implements IDisposable
then we can use using
keyword with the object of that class. But if I want to use using
keyword with the object of my own class then how can I use it.
If I had to implement IDisposable
in my own class then I have to also write the code for its Dispose()
method in my class. Then there is no point of using the using
keyword here when I am writing my own code in Dispose()
method. Then how can I use using in a user defined type (like classes & structs).
Please explain with some example.