Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

!: practical reference

!: practical reference: ! negates a bool or calls an overloaded operator; postfix ! separately means null-forgiving.

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

Syntax

!operand

! negates a bool or calls an overloaded operator; postfix ! separately means null-forgiving.

Use it for a simple condition reversal, preferring named predicates for complex logic.

Repeated negation hurts readability and an overload can implement unusual behavior.

Nullable needs explicit null handling; !null is not a valid bool expression.

The complete program actually uses !; its exact expected stdout is True.

Examples

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

Console.WriteLine(!false);

Result

True

The complete program actually uses `!`; its exact expected stdout is `True`.

Sources