该问题可能是重复问题,可以参考上述链接了解在C#中波浪号(~)的含义。可能是重复问题:
什么是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);
}
波浪线在这一行上有什么作用?
我认为它是按位取反运算符,事实上我并不真正理解那整个块(注释行和括号块),它既不是方法,也不是参数或任何东西,它是什么以及为什么在它之前有一个波浪线?