像其他人一樣,他們是位運算符。 FontStyle
是一個位域(一組標誌)。
oldf.Style & ~FontStyle.Bold
這意味着「去掉粗體」但看着下面的數學,你會得到這樣的事情。
(a) FontStyle.Bold = 0b00000010; // just a guess, it doesn't really matter
(b) oldf.Style = 0b11100111; // random mix here
// we want Bold "unset"
(c) ~FontStyle.Bold = 0b11111101;
=> (b) & (c) = 0b11100101; // oldf without Bold
new Font(oldf, oldf.Style | FontStyle.Bold)
這意味着我們要加粗的字體。通過將其與現有值進行或運算(這也意味着已經是大膽的東西將保持大膽)。
(a) FontStyle.Bold = 0b00000010; // just a guess, it doesn't really matter
(b) oldf.Style = 0b11100000; // random mix here
=> (b) | (c) = 0b11100010; // oldf with Bold