I have the following code
Font oldf;
Font newf;
oldf = this.richText.SelectionFont;
if (oldf.Bold)
newf = new Font(oldf, oldf.Style & ~FontStyle.Bold);
else
newf = new Font(oldf, oldf.Style | FontStyle.Bold);
I know that code, but I don’t know what did it mean these symbols &,| and ~ .
is these mean ( and , or , not ) or Am I wrong ?
Like others have stated, they are bitwise operators.
FontStyleis a bit field (set of flags).This means “remove bold” but looking at the underlying math, you get something like this.
This means that we want to Bold the font. By OR’ing it with the exist value (this also means that something that’s already bold will remain bold).