#defines

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From other postings I am of the impression that C# does not support #define
directives for the purposes of defining bit mask definitions such as the
following...

#define val10x00000001
#define PermPSSUser 0x00000002
#define PermBackupUser 0x00000004
 
Philip said:
From other postings I am of the impression that C# does not support #define
directives for the purposes of defining bit mask definitions such as the
following...

#define val10x00000001
#define PermPSSUser 0x00000002
#define PermBackupUser 0x00000004

Indeed. Depending on what the use is, you either use #define along with
#if etc, for conditional compilation, or const for constants, or
enumerations where appropriate.
 
You're right. The #define directive in C# is used for conditional
compilation only.

You should use enum's instead, for example:

[Flags]
public enum Perm
{
Value1 = 0x00000001,
PSSUser = 0x00000002,
BackupUser = 0x00000004
};

The [Flags] attribute is a hint for the compiler that binary operations (&,
|, ^, ~) can be applied to the enum members.

HTH,
Stefan
 
That is correct. Defines are only used as compile switches.
As in:
#define MYSWITCH
.....

#if MYSWITCH //where MYSWITCH is defined either in the project's properties
or at the beginning of the code file.
....
#endif

Chuck
 
Back
Top