C# equivalent to C's #define

S

Scott

What is the equivalent way to #define a variable and value
in C#?

I am porting a program with multiple #define's as such:

#define TIFF_VERSION 42
#define TIFF_BIGENDIAN 0x4d4d
#define TIFF_LITTLEENDIAN 0x4949

C# supports #define but not adding a value to it.
Is there a better way to do this in C#?

Scott
 
J

Jay B. Harlow [MVP - Outlook]

Scott,
I would use either const or enum. const for non-related values (PI), enum
for related values (such as days of weeks).

const int TIFF_VERSION = 42;
const int TIFF_BIGENDIAN = 0x4d4d;
const int TIFF_LITTLEENDIAN = 0x4949;

enum TIFF
{
VERSION = 42,
BIGENDIAN = 0x4d4d,
LITTLEENDIAN = 0x4949
}


Note, const needs to be within a class definition, enum can be inside or
outside of a class.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top