2009-12-10 76 views
3

用於〜字符我今天跨越這段代碼傳來:什麼是C#

File.SetAttributes(excelFileName, File.GetAttributes(excelFileName) & ~ 
        (FileAttributes.Archive | FileAttributes.ReadOnly)); 

之前從未見過。有人知道嗎?

回答

9

「什麼是在C#用於〜字符」(在不同的上下文

對於信息,〜還用於表示析/終結:

class Person { 
    public Person() {...} // constructor 
    ~Person() {...} // destructor 
} 

請注意,你很少有需要析構函數;通常只有當您的類型直接包裝非託管資源(操作系統句柄等)。你看這通常用於

1

一個地方是在種子初始化:

Random randomGen = new Random(~(int)DateTime.Now.Ticks); 
Random otherGen = new Random((int)DateTime.Now.Ticks); 

即使這些大致發生在相同的「滴答」,他們將與兩個不同的種子播種。