gpt4 book ai didi

c# - C# 中的 "|="运算符是什么?

转载 作者:行者123 更新时间:2023-11-30 19:10:29 24 4
gpt4 key购买 nike

在研究错误的原因时,我遇到了这行代码:

Status |= (int)states.Reading;

C# 中的“|=”运算符是什么?

“状态”是这样定义的:

public static int Status 

...使用访问器和修改器(或“getter”和“setter”),而“states”是这样定义的:

[Flags]
public enum states

最佳答案

它是“按位逻辑或”运算符,定义为 here.

x |= y 等同于 x = x | y

此外,如果您想了解更多关于“|”的信息运营商本身,你可以这样做here.

关于c# - C# 中的 "|="运算符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17368436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com