我总是很惊讶,即使现在使用C#后,我仍然设法找到我不知道的事情...
我已经尝试搜索互联网这个,但是在搜索中使用“〜”对我来说不是很好,我没有在MSDN上找到任何东西(不要说它不在那里)
我最近看到这段代码,波浪号(〜)是什么意思?
/// <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'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about...
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)
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??
最满意答案
〜是一元的补码运算符 - 它翻转其操作数的位。
~0 = 0xFFFFFFFF = -1在二进制补码运算中, ~x == -x-1
〜操作符可以从C语言中找到,其中包括Objective-C / C ++ / C#/ Java / Javascript。
~ is the unary one's complement operator -- it flips the bits of its operand.
~0 = 0xFFFFFFFF = -1in two's complement arithmetic, ~x == -x-1
the ~ operator can be found in pretty much any language that borrowed syntax from C, including Objective-C/C++/C#/Java/Javascript.
更多推荐
发布评论