这个波浪号在 C# 中的用途是什么

What is the purpose of this tilde in C#

我正在尝试移植此 C# 代码:

public static ulong WILDCARD_COLLISION_TYPE
{
    get
    {
        int parse = ~0;
        return (ulong)parse;
    }
}

如果我没理解错的话,~ 符号不是执行按位补码,那么 ~0 有什么意义呢?然后退货?

来自~ Operator documentation

The ~ operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. Bitwise complement operators are predefined for int, uint, long, and ulong.

例如:

unsigned int i = ~0;

Result: Max number I can assign to i

and

signed int y = ~0;

Result: -1

所以更多信息我们可以说 ~0 只是一个所有位都设置为 1. 的 int 当解释为无符号时,这将等同于 UINT_MAX。当解释为签名时,这将是 -1