0

I frequently read code like this:

System.Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations | System.Diagnostics.DebuggableAttribute.DebuggingModes.EnableEditAndContinue | System.Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | System.Diagnostics.DebuggableAttribute.DebuggingModes.Default) 

in C# program,sometimes parameter like this,what's this meanning ?

I have searched from google,but has no valuable answer,the '|' can not property parsing in Google engine,maybe i use the wrong way when searching.

2
  • when | is used as || it is OR operator and here it used as Enum values Commented Dec 8, 2013 at 13:36
  • see msdn Commented Dec 8, 2013 at 13:37

5 Answers 5

4

'|' is the bitwise or operator, in this case it is used to create an enum value with all the given bits set.

DebuggingModes is a bitflag enumeration - this means each bit can indicate a flag and a single DebuggingModes value can be used to signal multiple flags.

Enums can be made bitflags using the BitFlagsAttribute:

[FlagsAttribute] public enum DebuggingModes { Default = 0, DisableOptimizations = 1, EnableEditAndContinue = 2, ... } 
Sign up to request clarification or add additional context in comments.

1 Comment

It depends. If you're comparing Booleans, it's a non-short-circuiting OR comparison (|| is short-circuiting). For integral types (which includes enums), it's indeed the bitwise OR.
3

In this case it seems that it is a Flags enum

[Flags] public enum Types { None = 0, Type1 = 1, Type2 = 2, Type3 = 4, } 

So

Types someType = Types.Type1 | Types.Type2; 

Would mean that it has both types.

Comments

1

It is a bitwise OR operator iin C#. Here it is used to create an enum value with all the given set of bits.

Binary | operators are predefined for the integral types and bool. For integral types, | computes the bitwise OR of its operands. For bool operands, | computes the logical OR of its operands; that is, the result is false if and only if both its operands are false.

Comments

1

It is a logical or operator. see here for a complete explanation.

Main explanation in the doc:

Binary | operators are predefined for the integral types and bool. For integral types, | computes the bitwise OR of its operands. For bool operands, | computes the logical OR of its operands; that is, the result is false if and only if both its operands are false.

Comments

0

when | is used as || it is OR operator and here it used as Enum values

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.