0
Why is using "using" important? As well how to make a class that can be declared inside of a using statement.
Can someone please explain. Thanks
2 Respostas
+ 2
It calls dispose on a disposable object as soon as it leaves the scope of the using statement or an exception occurs. This is useful for ensuring you dont forget to do it and have things like memory/resources being leaked
+ 1
You need to implement the Idisposable interface which contains the Dispose methode.
In the dispose methode you need to define what your class needs to do when the object is now longer in use.
The using statement is esspecially handy when you need the object for a short defined moment.
using {
open file
read data
close file
}