什么';s"|&引用;在C#编程中是什么意思?
我经常阅读这样的代码:什么';s"|&引用;在C#编程中是什么意思?,c#,C#,我经常阅读这样的代码: System.Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations | System.Diagnostics.DebuggableAttribute.DebuggingModes.EnableEditAndContinue | System.Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoin
System.Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations | System.Diagnostics.DebuggableAttribute.DebuggingModes.EnableEditAndContinue | System.Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | System.Diagnostics.DebuggableAttribute.DebuggingModes.Default)
在C#程序中,有时像这样的参数,这是什么意思
我从google搜索过,但没有有价值的答案,“|”不能在google引擎中进行属性解析,可能我在搜索时使用了错误的方法。“|”是按位
或
运算符,在本例中,它用于创建所有给定位设置的枚举值
DebuggingModes
是位标志枚举-这意味着每个位可以表示一个标志,单个DebuggingModes
值可以用来表示多个标志
可以使用BitFlagsAttribute
将枚举设为位标志:
[FlagsAttribute]
public enum DebuggingModes
{
Default = 0,
DisableOptimizations = 1,
EnableEditAndContinue = 2,
...
}
这是一本书。在这里,它用于创建一个包含所有给定位集的
二进制|运算符是为整数类型和bool预定义的。对于
整数类型,|计算其操作数的按位或。为布尔
操作数,|计算其操作数的逻辑OR;就是
结果为false当且仅当其两个操作数都为false时
它是一个逻辑
或运算符。有关完整的解释,请参阅
文件中的主要说明:
二进制|运算符是为整数类型和bool预定义的。对于整数类型,|计算其操作数的按位OR。对于布尔操作数,|计算其操作数的逻辑OR;也就是说,当且仅当其两个操作数都为false时,结果为false。在本例中,它似乎是一个
所以
这意味着它有两种类型。当|用作| | |它是或运算符时,这里它用作枚举值当|用作| | |它是或运算符时,这里它用作枚举值视情况而定。如果你在比较布尔值,这是一个非短路或比较(|
是短路)。对于整数类型(包括枚举),它实际上是按位OR。
[Flags]
public enum Types
{
None = 0,
Type1 = 1,
Type2 = 2,
Type3 = 4,
}
Types someType = Types.Type1 | Types.Type2;