Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / C#

not: riferimento pratico

not: riferimento pratico: not nega un pattern in is o switch.

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

Sintassi

not /* grammar-specific form */

not nega un pattern in is o switch.

Usalo per escludere chiaramente un tipo, null o un intervallo.

La precedenza con and e or può sorprendere; aggiungi parentesi.

Dichiarare una variabile di pattern sotto not produce l’errore di compilazione CS8780; non è solo una questione di disponibilità successiva o definite assignment.

Il programma completo usa realmente not; lo stdout esatto atteso è True.

Esempi

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);

Risultato

True

Il programma completo usa realmente `not`; lo stdout esatto atteso è `True`.

Fonti