More Intuitive Syntax for Manifest (enum) Constants

Kapendev alexandroskapretsos at gmail.com
Tue Nov 25 01:58:54 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.
>
> 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?
> }
>
> [DllImport("NativeLib.dll")]
> public static extern BadNativeResult GetLastError();

Not sure, but if you really care then just add a type to the enum.

> standard
> robust
> safe
> recommended solution

Source?????


More information about the Digitalmars-d mailing list