LFInteractive Docs
  • Programming Documentation
  • C#
    • Installing Visual Studio
    • Understanding C#
      • Namespaces
      • Classes
      • Enum
      • Variables
        • Static Types
        • Primitive Types
        • Access Modifiers
        • Variables vs Properties
        • Nullable Variables
      • Getters and Setters
      • Solution vs Project
      • Struct vs Class
      • Coding Conventions
      • Tasks and Async
        • Parallel Tasks
      • Methods
      • PreProcessor Statements
    • Creating Your First Console App
      • Class Library
        • Models
          • File Model
          • Result Model
        • Controllers
          • File Controller
          • File System Controller
      • Console App
        • Nuget Packages
        • Main Method
    • Minecraft.NET
      • Minecraft.NET Library
      • Modrinth.NET Library
      • CurseForge.NET Library
      • Fabric.NET Library
    • Common Lib
      • Strings
      • Advanced Network Client
      • Advanced Timer
      • Advanced File Info
      • Configuration File
      • Application Config
      • Database File
      • Crypt Class
  • C++
    • Networking
      • Windows Socket (Client)
    • cclip
    • VCPKG
    • spdlog
      • Getting Started
      • Patterns
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. C#
  2. Understanding C#

PreProcessor Statements

Preprocessor statements are special instructions that are processed by the compiler before the actual compilation of your code takes place. These statements begin with a hash symbol (#) and provide a way to include or exclude certain sections of code based on specific conditions. They are used to control the compilation process and influence how the code is compiled.

Here are a few common preprocessor statements and their purposes:

  1. #if, #else, and #endif: These statements are used to conditionally include or exclude blocks of code based on certain conditions. For example, you can use #if to check if a specific symbol or constant is defined, and if it is, the code within the corresponding #if block will be included during compilation. If the condition is not met, the code within the #else block (if present) or outside any conditional block will be compiled.

  2. #define and #undef: These statements are used to define or undefine symbols that can be checked with #if statements. For example, you can define a symbol using #define and then use #if to conditionally include or exclude code based on whether that symbol is defined or not.

  3. #warning and #error: These statements are used to generate warnings or errors during compilation. #warning allows you to display custom warning messages in the compilation output, while #error forces the compiler to stop and display an error message.

Preprocessor statements provide a way to customize the compilation process and make your code more flexible and adaptable. They are often used for conditional compilation, allowing you to create different versions of your code for different scenarios or configurations.

It's worth noting that preprocessor statements are resolved at compile-time and do not affect the runtime behavior of the code. They are primarily used during the development and build process to control how the code is compiled and which parts are included or excluded based on specific conditions.

PreviousMethodsNextCreating Your First Console App

Last updated 2 years ago

Was this helpful?