Skip to content

FR CSharp Directive Define

Codex edited this page Oct 11, 2026 · 2 revisions

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

Compiler des symboles

Manuel C# · Guide pratique

#define déclare un caractère local, #undef le remplace. Les directives sont placées avant le premier jeton de fichier normal.

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
#define REPORT
#undef REPORT
#if REPORT
System.Console.WriteLine("Enabled");
#else
System.Console.WriteLine("Disabled");
#endif

Résultat:

Disabled

Syntaxe

#define NAME / #undef NAME

Exemple 1

#define REPORT
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)
    {
        #if REPORT
        Console.WriteLine("Report");
        #endif
    }
}

Exemple 2

#define REPORT
#undef REPORT
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)
    {
        #if REPORT
        Console.WriteLine("Report");
        #else
        Console.WriteLine("Disabled");
        #endif
    }
}

Source officielle : Microsoft Apprendre.

Clone this wiki locally