什么是在枚举定义的符号(〜)? [英] What is the tilde (~) in the enum definition?
问题描述
我总是感到惊讶,即使是现在使用C#这一切的时间后,我还是设法找到的东西我不知道...
I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about...
我试图寻找上网本,但使用〜在搜索中不工作对我这么好,我没有在MSDN上找到任何事(不是说这是不存在的)
I've tried searching the internet for this, but using the "~" in a search isn't working for me so well and I didn't find anything on MSDN either (not to say it isn't there)
我看到了code最近,什么是波浪号(〜)指的这个片段?
I saw this snippet of code recently, what does the tilde(~) mean?
/// <summary>
/// Enumerates the ways a customer may purchase goods.
/// </summary>
[Flags]
public enum PurchaseMethod
{
All = ~0,
None = 0,
Cash = 1,
Check = 2,
CreditCard = 4
}
我是看到它,所以我试着编译它有些惊讶,和它的工作...但我仍然不知道这是什么意思/一样。任何帮助??
I was a little surprised to see it so I tried to compile it, and it worked... but I still don't know what it means/does. Any help??
推荐答案
〜是一元的补运营商 - 它翻转操作数的位
~ is the unary one's complement operator -- it flips the bits of its operand.
~0 = 0xFFFFFFFF = -1
在补运算,〜点¯x== -x-1
〜运算符可以在pretty找到太多,借鉴了C语法,其中的Objective-C / C ++ / C#/的Java / Java脚本的任何语言。
the ~ operator can be found in pretty much any language that borrowed syntax from C, including Objective-C/C++/C#/Java/Javascript.
这篇关于什么是在枚举定义的符号(〜)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!