I am looking at some code and it has this statement:
~ConnectionManager() { Dispose(false); }
The class implements the IDisposable interface, but I do not know if that is part of that the tilde(~) is used for.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No related questions found
~ is the destructor
Finalize
In C#, the Finalize method performs the operations that a standard C++ destructor would do. In C#, you don’t name it Finalize — you use the C++ destructor syntax of placing a tilde ( ~ ) symbol before the name of the class.
Dispose
It is preferable to dispose of objects in a
Close()orDispose()method that can be called explicitly by the user of the class. Finalize (destructor) are called by the GC.The IDisposable interface tells the world that your class holds onto resources that need to be disposed and provides users a way to release them. If you do need to implement a finalizer in your class, your Dispose method should use the
GC.SuppressFinalize()method to ensure that finalization of your instance is suppressed.What to use?
It is not legal to call a destructor explicitly. Your destructor will be called by the garbage collector. If you do handle precious unmanaged resources (such as file handles) that you want to close and dispose of as quickly as possible, you ought to implement the IDisposable interface.