Pre-Processor Compilation Directives
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:Tutorials |
| C# Tutorials |
C# Preprocessor Directives
|
| edit |
Contents |
Warning Directive
The most useful command by far in this group is the #warning command. When coding you find yourself adding TODO comments all over the code, especially if you develop in a team environment. Such comments are useful when you want to remember to add more functionality to that piece of code. However, it does not help a single bit if you end up forgetting to do a search for your todos at the end. The #warning command stops you from forgetting by adding the text from the right of the command into the warnings window when you compile your code.
It is important to still add TODO in the text to allow for easy searching of them when outside of the main code editor or by people who may not be familiar with the #warning directive.
Example
If you want to see any real warnings then just click the Description header to sort by description. Then all of the #warning warnings will be grouped together at either the top or bottom ready for you to come back to later.
Error Directive
The #error directive is only usefully if you need to remember to do something else before you compile your application, as it will stop the compilation process and flag an error.
Example
If you want to see any real errors then just click the Description header to sort by description. Then all of the #error errors will be grouped together at either the top or bottom ready for you to come back to later.
Line Directive
The line directive has many possible uses, the most useful of them allows you to hide code from the debugger. This allows you to concentrate on a particular part of the code when debugging.
Example
The line directive has many possible uses, the most useful of them allows you to hide code from the debugger. This allows you to concentrate on a particular part of the code when debugging.
It is important to remember that the code still executes on the hidden lines.




