Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

notnull: referência prática

notnull: referência prática: notnull exige um tipo non-nullable quando nullable annotations estão ativas.

Versão: C# language; verified against C# 14 reference

Sintaxe

notnull /* grammar-specific form */

notnull exige um tipo non-nullable quando nullable annotations estão ativas.

Usa-o em API generic cujas chaves ou valores não permitem null.

É sobretudo um aviso de análise, não runtime validation completa.

Não distingue struct de class; oblivious code pode contornar o aviso.

O programa completo usa realmente notnull; o stdout exato esperado é ok.

Exemplos

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;

Console.WriteLine(Echo("ok")); static T Echo<T>(T value) where T : notnull => value;

Resultado

ok

O programa completo usa realmente `notnull`; o stdout exato esperado é `ok`.

Fontes