Categories
.NET .NET 10 ASP.NET Core Aspire Automation Azure Blazor C# CLI Code Desktop Developer Getting Started Linux macOS Mobile Visual Studio VS Code Web What's New Windows

Using C# Ignored Directives: A Guide for Programmers

C# – Preprocessor Directives are highly useful for writing code that can be compiled conditionally, depending on factors like the target framework, target platform, or build configuration.

For example:

#if NET9_0_OR_GREATER
// The code within this block will execute only on .NET 9 or higher
#endif

#if ANDROID
// The code within this block will execute only on the Android OS
#endif

#if DEBUG
// The code within this block will execute only in Debug mode
#endif

C# – Ignored Directives have a similar syntax but are ignored by the compiler because they are for tooling.

The real purpose of this feature is to execute a C# source file directly from the CLI. It doesn’t need a project file. Now, even the plain console app requires a project file, despite the much-simplified top-level statements feature.

Categories
.NET .NET 8 .NET 9 .NET MAUI Android Blazor C# Desktop Developer Events F# General Hybrid iOS macOS Mobile Standup Visual Studio VS Code Web What's New Windows Xamarin Xamarin.Forms

Join the October .NET MAUI Community Standup

This October, join David and Rachel as they discuss the latest developments in the realm of .NET MAUI during the monthly community standup.

Remember to join live on Thu, Oct 3 at 17:00 UTCClick the link to access the timing in your local or preferred time zone. Note, that it’s back to its usual schedule.

Update: The community links for this month’s standup will be updated here.

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.