Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

not: practical reference

not: practical reference: not negates a pattern in is or switch.

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

Syntax

not /* grammar-specific form */

not negates a pattern in is or switch.

Use it to exclude a type, null, or a range clearly.

Its precedence with and and or can surprise, so add parentheses for intent.

Declaring a pattern variable beneath not is compile-time error CS8780; this is not merely a question of its later availability or definite assignment.

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

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

object? value = null; Console.WriteLine(value is not string);

Result

True

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

Sources