开发者

What is ~ in C#? [duplicate]

开发者 https://www.devze.com 2023-02-24 19:13 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: What is the tilde (~) in a C# enumeration?
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

What is the tilde (~) in a C# enumeration?

What does the tilde mean in an expression?

I have download a CRC code snippet from the internet in C# having these lines:

byte[] hashBuffer = UInt32ToBigEndianBytes(~hash);

or

public static UInt32 Compute(byte[] buffer)
{
   return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length);
}开发者_如何学运维


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.

From: http://msdn.microsoft.com/en-us/library/d2bd4x66.aspx

And although it is not used this way in the example you have shown, the ~ character is also used to declare a destructor in C#.


Take a look at MSDN: ~ Operator

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号