#define预处理器 [英] #define preprocessor

查看:269
本文介绍了#define预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在C#中执行以下操作,(下面的定义行)


c / c ++:#define MAX_LEN 0x23


for (int i = 0; i< MAX_LEN; ++)

array [i] = 0xFF;

how I can do the following in C#, (the define line below)

c/c++ : #define MAX_LEN 0x23

for (int i=0;i<MAX_LEN;++)
array[i] = 0xFF;

推荐答案

[ Yosi]写道:
[Yosi] wrote:
我如何在C#中执行以下操作,(下面的定义行)

c / c ++:#define MAX_LEN 0x23
for(int i = 0; i< MAX_LEN; ++)
array [i] = 0xFF;
how I can do the following in C#, (the define line below)

c/c++ : #define MAX_LEN 0x23

for (int i=0;i<MAX_LEN;++)
array[i] = 0xFF;




不是*完全*相同,但是你可以使用


private const int MAX_LEN = 0x23;

(或public而不是private)

>
-

Hans Kesting



not *exactly* the same, but you could use

private const int MAX_LEN = 0x23;
(or "public" instead of "private")

--
Hans Kesting


不,这不是我需要的,你的建议分配内存(sizeof

(int)),在我的项目中有超过200个常量(定义),这将是

需要200 * 4 = 800字节。

什么我需要的是在运行编译器时所有MAX_LEN都将c被绞死是我定义的数字(预编译器)。

" Hans Kesting"写道:
No , this is not what I need , your suggestion allocate memory (sizeof
(int)), In my project there are more than 200 constants (define) , this will
need 200*4 = 800 bytes.
What I need is while running the compiler all the MAX_LEN will changed to be
the number I defined (pre compiler).
"Hans Kesting" wrote:
[Yosi]写道:
我如何在C#中执行以下操作,(下面的定义行)

c / c ++:#define MAX_LEN 0x23
for(int i = 0; i< MAX_LEN; ++)
array [i] = 0xFF;
how I can do the following in C#, (the define line below)

c/c++ : #define MAX_LEN 0x23

for (int i=0;i<MAX_LEN;++)
array[i] = 0xFF;



不*完全*相同,但你可以使用

私有const int MAX_LEN = 0x23;
(或public而不是private)

-
Hans Kesting



not *exactly* the same, but you could use

private const int MAX_LEN = 0x23;
(or "public" instead of "private")

--
Hans Kesting



在C ++中有一个预处理器可以对以#开头的行做出反应。

在C#中没有单独的预处理器,相反你应该使用const

关键字实现''几乎''相同。


Gabriel Lozano-Morán


" [Yosi]" <哟** @ discussions.microsoft.com>在消息中写道

新闻:1B ********************************** @ microsof t.com ...
In C++ there is a preprocessor that will react to the lines starting with #.
In C# there is no seperate preprocessor, instead you should use the const
keyword to achieve ''almost'' the same.

Gabriel Lozano-Morán

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
不,这不是我需要的,你的建议分配内存(sizeof
(int)),在我的项目中有超过200个常量(定义) ,这个
需要200 * 4 = 800字节。
我需要的是在运行编译器时所有的MAX_LEN都会改为

我定义的数字(预编译器)。

" Hans Kesting"写道:
No , this is not what I need , your suggestion allocate memory (sizeof
(int)), In my project there are more than 200 constants (define) , this
will
need 200*4 = 800 bytes.
What I need is while running the compiler all the MAX_LEN will changed to
be
the number I defined (pre compiler).
"Hans Kesting" wrote:
[Yosi]写道:
>我如何在C#中做到以下几点(下面的定义行)
>
> c / c ++:#define MAX_LEN 0x23
>
> for(int i = 0; i< MAX_LEN; ++)
> array [i] = 0xFF;
> how I can do the following in C#, (the define line below)
>
> c/c++ : #define MAX_LEN 0x23
>
> for (int i=0;i<MAX_LEN;++)
> array[i] = 0xFF;



不*完全*相同,但你可以使用

private const int MAX_LEN = 0x23;
(或公共而不是私人)

-
Hans Kesting



not *exactly* the same, but you could use

private const int MAX_LEN = 0x23;
(or "public" instead of "private")

--
Hans Kesting



这篇关于#define预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆