1. 程式人生 > >【已解決】C#中的#ifdef

【已解決】C#中的#ifdef

ref: https://www.crifan.com/csharp_implement_the_ifdef_effect/

 

【問題】

想要在C#中實現,#ifdef的效果。

 

【解決過程】

1.之前就沒找打解決方法。

2.後來參考:

#ifdef in C#

去試了試,得知,原來直接使用#if,就可以了。

是否想要使用相關的程式碼,通過

定義

不定義

對應的巨集,即可實現。

 

比如:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

//comment out following macros if not use them

#define USE_DATAGRIDVIEW

 

#if USE_DATAGRIDVIEW

using Excel = Microsoft.Office.Interop.Excel;

using Microsoft.Office.Interop.Excel;

#endif

 

#if USE_DATAGRIDVIEW

    /*********************************************************************/

    /* DataGridView */

    /*********************************************************************/

 

    public void dgvClearContent(DataGridView dgvValue)

    {

        dgvValue.Rows.Clear();

    }

#endif

 

【總結】

C#中,其實就是把別的語言(C,C++等)中的#ifdef,換成了#if。

轉載請註明:在路上 » 【已解決】C#中的#ifdef