返回顶部

收藏

C# 的预处理器

更多

http://www.codeproject.com/KB/cs/predirectivescsharp.aspx

[C#]代码

#define Default
#define DovelopmentMode
#define TestingMode
#undef  DovelopmentMode

#if DEBUG
#warning You should not compile in debug mode, use release mode         
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            String orgName=String.Empty;
            String email=String.Empty;
            String SourceDb=String.Empty;

            #if(DovelopmentMode)
              {
              SourceDb="C:\\DovDb.Mdb"; //This Db used at the time of dovelopment phase
              }
            #else
              {
              SourceDb = "C:\\TestDb.Mdb";//This Db used at the time of testing
              }
            #endif

            #if(Default)
            {
                orgName = "MyOrganization";            
                email = "Default@gmail.com";
                const string logName = @"\myLog.log";  //Write log information
            }
            #else
            {   
                orgName = fetch from database
                email = fetch from database
               const string logName = fetch from database //Write log information
            }
            #endif

        }

    }
}

标签:c#

收藏

0人收藏

支持

0

反对

0

发表评论