C# equivalent to C's #define

  • Thread starter Thread starter Scott
  • Start date Start date
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
 
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
 
Back
Top