L
LPeter
Hi,
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B','C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F','G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J','K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0' << 24)),
public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
public None = FOURCC('\0','\0','\0','\0'),
public A = FOURCC('A','B','C','D'),
public B = FOURCC('E','F','G','H'),
public C = FOURCC('I','J','K','L')
}
Thanks for any good suggestion.
LPeter
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B','C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F','G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J','K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0' << 24)),
public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
public None = FOURCC('\0','\0','\0','\0'),
public A = FOURCC('A','B','C','D'),
public B = FOURCC('E','F','G','H'),
public C = FOURCC('I','J','K','L')
}
Thanks for any good suggestion.
LPeter