【已解决】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

猜你喜欢

转载自blog.csdn.net/kuangben2000/article/details/85101107