C#中使用的〜字符是什么

Mic*_*cah 3 c#

我今天遇到了这段代码:

File.SetAttributes(excelFileName, File.GetAttributes(excelFileName) & ~
                   (FileAttributes.Archive | FileAttributes.ReadOnly));
Run Code Online (Sandbox Code Playgroud)

从未见过它.谁知道?

THE*_*TOR 13

http://msdn.microsoft.com/en-us/library/d2bd4x66.aspx

〜运算符对其操作数执行按位补码运算,具有反转每个位的效果.为int,uint,long和ulong预定义了按位补码运算符.


Mar*_*ell 9

"C#中使用的〜字符是什么"

对于info,〜也用于(在不同的上下文中)表示析构函数/终结符:

class Person {
    public Person() {...} // constructor
    ~Person() {...} // destructor
}
Run Code Online (Sandbox Code Playgroud)

请注意,您很少需要析构函数; 通常只有当您的类型直接包装非托管资源(操作系统句柄等)时.