Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

~: practical reference

~: practical reference: ~ flips every bit of an integral operand or invokes a user-defined overload.

Version: C# language; verified against C# 14 reference

Syntax

~operand

~ flips every bit of an integral operand or invokes a user-defined overload.

Apply it with a mask limited to the intended width.

For signed values the sign bit is also flipped, so the result is commonly negative.

Promoting smaller operand types to int changes the width of the operation.

The complete program actually uses ~; its exact expected stdout is -1.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

Console.WriteLine(~0);

Result

-1

The complete program actually uses `~`; its exact expected stdout is `-1`.

Sources