Skip to content

FR CSharp Operator Null Forgiving

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

Suppression des avertissements nullables

Manuel C# · Guide pratique

Indique à l'analyse nullable que l'expression est traitée comme non-null. Ne vérifie pas la valeur et ne protège pas contre NullReferenceException.

Exemple simple (Example.cs)

Enregistrez cet exemple séparément dans Example.cs. Exécutez-le indépendamment des autres exemples de cette page.

Example.cs:

// PROJECT-EXAMPLE
string? name = "ore";
System.Console.WriteLine(name!.Length);

Résultat:

3

Syntaxe

possiblyNull!.Member

Exemple 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        string? text = "ore";
        Console.WriteLine(text!.Length);
    }
}

Exemple 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Dictionary<string, string> values = new() { ["name"] = "Archer" };
        values.TryGetValue("name", out string? name);
        Console.WriteLine(name!.ToUpperInvariant());
    }
}

Source officielle : Microsoft Apprendre.

Clone this wiki locally