
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is a pre-processor directive in C#?
C# compiler does not have a separate preprocessor; however, the directives are processed as if there was one. In C# the preprocessor directives are used to help in conditional compilation.
The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts.
The following are the preprocessor directives in C# −
Sr.No. | Preprocessor Directive & Description |
---|---|
1 | #define It defines a sequence of characters, called symbol. |
2 | #undef It allows you to undefine a symbol. |
3 | #if It allows testing a symbol or symbols to see if they evaluate to true. |
4 | #else It allows to create a compound conditional directive, along with #if. |
5 | #elif It allows creating a compound conditional directive. |
6 | #endif Specifies the end of a conditional directive. |
7 | #line It lets you modify the compiler's line number and (optionally) the file name output for errors and warnings. |
8 | #error It allows generating an error from a specific location in your code. |
9 | #warning It allows generating a level one warning from a specific location in your code. |
10 | #region It lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. |
11 | #endregion It marks the end of a #region block. |
Let us see an example to learn about the usage of pre-processor directive in C# −
Example
#define PI using System; namespace Demo { class Program { static void Main(string[] args) { #if (PI) Console.WriteLine("PI is defined"); #else Console.WriteLine("PI is not defined"); #endif Console.ReadKey(); } } }
- Related Articles
- What is a conditional pre-processor directive in C#?
- What is #define pre-processor directive in C#?
- What are C# pre-processor directives?
- What are the Pre-processor Commands in C language?
- Explain the pre-processor directives in C language
- What is a page directive in JSP?
- What is a include directive in JSP?
- What is a taglib directive in JSP?
- What is a @extend directive in SASS?
- What is Superscalar Processor?
- What is CISC Processor?
- What is RISC Processor?
- Pre-increment (or pre-decrement) in C
- #pragma Directive in C/C++
- What Is Pre-existing cell

Advertisements