IDisposable
-
I am wondering, what is the point of implementing IDisposable? Why not just do whatever is needed in the destructor?
C# dosen't have a delete operator so, we don't have destructors in the C++ sense. You have to override the finalize method which looks strangely like a C++ destructor :) But, in order to exercise a more percise destructor like control .net wants us to implement the Dispose pattern which can be easily done through IDisposable. Another bennifit is that much of .net uses this pattern; also a client app using your class class will be able test for this interface using the "as" or "is" operators..making it a tad more reuasable. Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that? - Jack Burton
-
I am wondering, what is the point of implementing IDisposable? Why not just do whatever is needed in the destructor?
Here's the answer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconfinalizedispose.asp[^] Remember, .NET doesn't have deterministic finalization. Hope this helps. Andres Manggini. Buenos Aires - Argentina.