More Intuitive Syntax for Manifest (enum) Constants

Kagamin spam at here.lot
Tue Nov 25 10:27:10 UTC 2025


On Monday, 24 November 2025 at 23:07:25 UTC, Peter C wrote:
> On Monday, 24 November 2025 at 15:46:28 UTC, Kagamin wrote:
>> ...
>> interoperable enums are better declared as integer or string 
>> constants.
>
> For those listening, please don't follow that advice.

After you said that constants should be declared as `const int` 
because enums are weird :)
You're not wrong, `const int` is the way to go in C#.

> Best practice, is that you should always consider explicitly 
> setting the underlying type of the C# enum to match the native 
> definition.
>
> Here's what happens when you don't follow best practice:
>
> public enum BadNativeResult
> {
>     SUCCESS = 0,
>     MAX_ERROR = 0xFFFFFFFF // what do you think will happen 
> here?
> }

The alternative is to not create a problem from the start.


More information about the Digitalmars-d mailing list