Search code examples
c#tilde

What does the tilde (~) character do here


Possible Duplicate:
What does the tilde (~) mean in C#?

class ResourceWrapper
{
    int handle = 0;
    public ResourceWrapper()
    {
        handle = GetWindowsResource();
    }
    ~ResourceWrapper()                     //this line here
    {
        FreeWindowsResource(handle);
        handle = 0;
    }
    [DllImport("dll.dll")]
    static extern int GetWindowsResource();
    [DllImport("dll.dll")]
    static extern void FreeWindowsResource(int handle);
}

What does the tilde do on the line indicated.

I thought that it was the bitwise NOT operator, infact I don't really understand that whole block there, (the commented line and the parentheses blovk after it), it isn't a methd, or a parameter or anything, what is it and why is there a tilde before it?


Solution

  • That is destructor. It takes care that all resources are released upon garbage collection.