~ Operator
Visual Studio .NET 2003
The ~ operator performs a bitwise complement operation on its operand. Bitwise complement operators are predefined for int, uint, long, and ulong.
~ expr
Where:
- expr
- An expression.
Remarks
User-defined types can overload the ~ operator (see operator).
Example
// cs_operator_bitwise_compl.cs
using System;
class Test
{
public static void Main()
{
Console.WriteLine("!0x{0:x8} = 0x{1:x8}", 8, ~8);
Console.WriteLine("!0x{0:x8} = 0x{1:x8}", -8, ~-8);
}
}
Output
!0x00000008 = 0xfffffff7 !0xfffffff8 = 0x00000007