More Intuitive Syntax for Manifest (enum) Constants

Peter C peterc at gmail.com
Mon Nov 24 23:07:25 UTC 2025


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();



More information about the Digitalmars-d mailing list