This question already has an answer here:
- Proper use of the IDisposable interface 15 answers
Feel free to mark this as duplicate but it's a question that's probably basics which I have come across during my interview preparations.
If I write following class.
Public Class Class1{
}
Will any of the following two be any different/beneficial in terms of when/how resource is disposed after it's use
var c=new Class1(); or
using(var c=new Class1())
{
}
If no difference between those, my next questions are reduntant. If second is better, the class1 must implement IDisposable ,
Provided I implement IDisposable
Public Class Class1:IDisposable
{
}
assuming there will be methods properties in the class. what would be correct way to implement.
Dispose method in this class, to make sure all resources are disposed correctly.
Aucun commentaire:
Enregistrer un commentaire