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

前端 未结 2 1243
温柔的废话
温柔的废话 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

提交回复
热议问题