no preprocessor directive ??

  • Thread starter Thread starter Marge Inoferror
  • Start date Start date
M

Marge Inoferror

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
 
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 said:
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.
 
Thanks, Jon! I appreciate it...


Jon Skeet said:
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.
 
Back
Top