3
Answers

Looking for clarification on | operator

james

james

21y
1.7k
1
Okay, I've seen the pipe (|) used in instances where you want to assign multiple values to a property. A prime example of this is the Anchor property of the System.Windows.Forms.Control class. i.e... // Anchor the button to the bottom right corner of the form button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right); This is setting two values for 1 property. I can not find any documentation on this, however. Both the MSDN and the C# Spec only refer to the pipe (|) as the bitwise OR operator, and does not reference anything about this use of it. Can someone clarify exactly how a property can have two values at the same time? Are there any articles on constructing custom classes using this type of device? thanks, -James
Answers (3)