像其他人一样,他们是位运算符。 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