473,513 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

no preprocessor directive ??

In C, I might do this:

#define MAX_COLS 50;
#define MAX_ROWS 10;

In C# that seems to be an error!

What's the best way of accomplishing the same thing?

I tried this, but I don't know if this is the way to go:

static const int maxCols = 50;
static const int maxRows = 10;

Thanks,
Marge


Nov 16 '05 #1
3 1193
Hi,

Yes, you should indeed use "static const" in C# where you would have
previously used "#define" to define simple constant values in C.
Jonathan Holmes

"Marge Inoferror" <in*****************@yahoo.com> wrote in message
news:Qc***************@newssvr28.news.prodigy.com. ..
In C, I might do this:

#define MAX_COLS 50;
#define MAX_ROWS 10;

In C# that seems to be an error!

What's the best way of accomplishing the same thing?

I tried this, but I don't know if this is the way to go:

static const int maxCols = 50;
static const int maxRows = 10;

Thanks,
Marge


Nov 16 '05 #2
Marge Inoferror <in*****************@yahoo.com> wrote:
In C, I might do this:

#define MAX_COLS 50;
#define MAX_ROWS 10;

In C# that seems to be an error!
Yup.
What's the best way of accomplishing the same thing?

I tried this, but I don't know if this is the way to go:

static const int maxCols = 50;
static const int maxRows = 10;


It's not quite - you don't specify "static" with "const" as the latter
implies the former. Just

const int MaxCols = 50;
const int MaxRows = 10;

is fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

Thanks, Jon! I appreciate it...
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Marge Inoferror <in*****************@yahoo.com> wrote:
In C, I might do this:

#define MAX_COLS 50;
#define MAX_ROWS 10;

In C# that seems to be an error!


Yup.
What's the best way of accomplishing the same thing?

I tried this, but I don't know if this is the way to go:

static const int maxCols = 50;
static const int maxRows = 10;


It's not quite - you don't specify "static" with "const" as the latter
implies the former. Just

const int MaxCols = 50;
const int MaxRows = 10;

is fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
9832
by: Boris Kuznetsov | last post by:
This occurs in an empty project when I add the following string: #using <mscorlib.dll> Can anyone tell me why would #using ... not be working???? MSDN says nothing about this error. Please...
16
4467
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the...
2
4892
by: Gustavo L. Fabro | last post by:
Greetings. Is there a way to run the preprocessor twice? Rephrasing that, is there a way to: #define SOMETHING #pragma OTHERTHING and have the preprocessor in somecode.cpp evaluate: ...
6
3111
by: olivier.grant | last post by:
Hi All, I'm trying to define a macro that will allow me to write the following code : #include MY_MACRO( NAME, SPACE ) and end up with the following preprocessed code : #include NAME.hpp
5
3985
by: _dwin | last post by:
Hi, Does anyone know how to implement your own preprocessor directive? For instance, I would like to have a directive which goes like: #<directive_name<parameters, ...> ie. #compress...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.