#if, #else, #endif in C# source code

前端 未结 2 1245
温柔的废话
温柔的废话 2021-01-14 02:10

I\'ve got a sample code from MSDN and I\'ve found code syntax I\'ve never seen before:

namespace Mvc3RemoteVal.Controllers 
{
        public class HomeContro         


        
相关标签:
2条回答
  • 2021-01-14 02:40

    Those are called preprocessor directives and exist since .NET 1.0. They allow you to define different compilation directives such as InMemDB and the compiler will evaluate or not the block if this variable has been defined. The documentation of the #if directive provides a more in-depth overview.

    In order to define a variable you could use the /define compiler option or use the Conditional compilation symbols in the Build tab of the properties of the project in Visual Studio:

    alt text

    0 讨论(0)
  • 2021-01-14 02:47

    These are not new features for Framework 4

    this are features you can use for development stage and testing: you can declare:

    #Define something
    

    and then

    #if something
    

    all the code that is in that "if" will be executed. all the code that isn't, won't.

    0 讨论(0)
提交回复
热议问题