Repository navigation
EN CSharp Directives
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Directives start with # at the beginning of the line: #if/#elif/#else/#endif, #define, #undef, #region, #endregion, #warning, #error, #line, #pragma, #nullable. They control compilation or diagnostics. #region organizes the editor, but does not create a scope.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
#define REPORT
#if REPORT
System.Console.WriteLine("Enabled");
#else
System.Console.WriteLine("Disabled");
#endifResult:
Enabled
#nullable enable
string? name = null;
UO.Print(name ?? "unknown");#if DEBUG
UO.Print("Debug configuration");
#else
UO.Print("Regular configuration");
#endifA typical project defines TargetFramework, LangVersion, Nullable, AllowUnsafeBlocks and other properties in .csproj. The syntax is determined by the compiler, and the available API is also determined by the target platform and dependencies.
Of the modern features of C#, raw strings, collection expressions, primary constructors, list patterns, required, advanced ref capabilities, extensions and properties with field are important. For exact terms of a particular version, use the official history of the language; preview capabilities are enabled by a separate project parameter.
Official documentation: Directives, language version and compilation options - Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE