什么呢| =(单管等于)和放大器; =(单等于符号)的意思 [英] what does |= (single pipe equal) and &=(single ampersand equal) mean

查看:150
本文介绍了什么呢| =(单管等于)和放大器; =(单等于符号)的意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面几行:

//Folder.Attributes = FileAttributes.Directory | FileAttributes.Hidden | FileAttributes.System | FileAttributes.ReadOnly;
Folder.Attributes |= FileAttributes.Directory | FileAttributes.Hidden | FileAttributes.System | FileAttributes.ReadOnly;


Folder.Attributes |= ~FileAttributes.System;
Folder.Attributes &= ~FileAttributes.System;

什么呢 | = (单管相等)和&安培; = (单个号相同)的意思是在c#结果
我想删除系统属性以保持其他...

what does |= (single pipe equal) and &= (single ampersand equal) mean in c#
i want to remove system attribute with keeping the others...

在此先感谢

推荐答案

他们复合分配运营,翻译(非常松散)

They're compound assignment operators, translating (very loosely)

x |= y;

x = x | y;

和同为&安培; 。有没有在关于隐式转换少数情况下多一点细节,目标变量只计算了一次,但基本上它的要点。

and the same for &. There's a bit more detail in a few cases regarding an implicit cast, and the target variable is only evaluated once, but that's basically the gist of it.

在非复合运营商而言, &安培; 是位与 | 是一个位或

In terms of the non-compound operators, & is a bitwise "AND" and | is a bitwise "OR".

编辑:在您希望这种情况下, Folder.Attributes&安培; =〜FileAttributes.System 。要理解为什么:

In this case you want Folder.Attributes &= ~FileAttributes.System. To understand why:


  • 〜FileAttributes.System 表示所有属性除了系统是一个按位NOT)

  • &安培; 表示结果是所有操作数的两边发生的属性

  • ~FileAttributes.System means "all attributes except System" (~ is a bitwise-NOT)
  • & means "the result is all the attributes which occur on both sides of the operand"

所以基本上充当面膜 - 的保留中出现的那些属性(一切除了系统)。一般来说:

So it's basically acting as a mask - only retain those attributes which appear in ("everything except System"). In general:


  • | = 将只添加的位目标

  • &安培; = 仅会的删除的从目标位

  • |= will only ever add bits to the target
  • &= will only ever remove bits from the target

这篇关于什么呢| =(单管等于)和放大器; =(单等于符号)的意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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