为什么枚举类型不能是System命名空间中整数类型的底层类型?

时间:2013-03-05 08:36:48

标签: c# enums

我最近做了很多PInvoke的事情,希望保持接近Windows API头文件。

在下面创建enum时,会出现此编译器错误:

Error   1   Type byte, sbyte, short, ushort, int, uint, long, or ulong expected 

为什么C#编译器不理解任何其他underlying types
C#编译器可以从uint转到System.UInt32,为什么不相反呢?

using System;
using System.Runtime.InteropServices;

using DWORD = System.UInt32;

namespace BeSharp.Win32
{
    [StructLayout(LayoutKind.Sequential)]
    internal class MOUSEINPUT
    {
        // ...
        MouseData mouseData; // DWORD
        // ...

        [Flags]
        internal enum MouseData : System.UInt32; // needs to be uint; you cannot do DWORD or System.UInt32 here
        {
            Nothing = 0x0000,
            XBUTTON1 = 0x0001,
            XBUTTON2 = 0x0002,
        }
        // ...
    }
}

0 个答案:

没有答案
相关问题