什么是一个单|或放大器;意思? [英] What does a single | or & mean?

查看:139
本文介绍了什么是一个单|或放大器;意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
什么是之间的diffference |和|| ?或者运营商结果
是什么| (管)在C#是什么意思?

我有一些代码,被写了另一名开发人员在办公室里,谁不是在此刻。我有一些工作要做他的代码,但我还没有碰到在此之前昏迷。我想在这里上搜索,但它去除我的|退出搜索线。我也不知道什么该符号的名称为,所以无法搜索它这样。

I have some code that was written by another developer in the office, who isn't in at the moment. I have some work to do on his code, but I have not coma across this before. I tried searching on here, but it strips my | out of the search line. I also don't know what the name for that symbol is, so couldn't search for it like that.

this.Action.Values[key] = (int)this.Action.Values[key] | 1;



我的问题是什么呢单一或做在这种情况下?

My question is what does the single or do in this instance?

推荐答案

酒吧(或管道), | 是一个逐位运营商,并解释它的最简单的方法是,它可以让我们的标志相结合。试想一下:

The Bar (or pipe), | is a bit-wise OR operator, and the easiest way of explaining it is that it allows us to combine flags. Consider:

[Flags]
public enum WindowFlags
{
    None = 0, 
    Movable = 1,
    HasCloseBox = 2,
    HasMinimizeBox = 4,
    HasMaximizeBox = 8
}

使用按位或运算,我们可以结合的标志,正是如此:

Using the bitwise-OR operator, we can combine flags, thusly:

WindowFlags flags = WindowFlags .Movable | WindowFlags .HasCloseBox | WindowFlags .HasMinimizeBox;

我们可以测试对于给定的标志时,使用:

We can "test" for a given flag, using:

bool isMovable = (flags & WindowFlags .Movable);



删除标志更是一个应变对眼球有点:

Removing flags is a bit more of a strain on the eyeballs:

flags &= ~WindowFlags.HasCloseBox;  // remove HasCloseBox flag

这篇关于什么是一个单|或放大器;意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆