是.NET枚举Blittable型? (编组)NET、Blittable

2023-09-03 03:02:26 作者:花龄残伤

显然有Blittable型的列表,所以到目前为止,我没有看到具体上枚举。他们是一般blittable?抑或是取决于它们是否有blittable基本类型中声明?

Apparently there's a list of blittable types and so far I don't see Enums specifically on it. Are they blittable in general? Or does it depend on whether they are declared with a blittable base type?

//e.g.
internal enum SERVERCALL : uint
{
    IsHandled = 0,
    Rejected = 1,
    RetryLater = 2,
}

参考耗尽:

Blittable和非Blittable型 默认封送的值类型 "Blittable and Non-Blittable Types" "Default Marshaling for Value Types"

推荐答案

枚举是Blittable型。从 枚举关键字的文档< /一>:

Enums are blittable types. From the enum keyword documentation:

每个枚举类型都有一个   基础类型,可以是任何   整型除了字符。

Every enumeration type has an underlying type, which can be any integral type except char.

由于底层类型是积分(所有这些都是Blittable型的名单上),则枚举也是blittable

Because the underlying type is integral (all of which are on the list of blittable types), the enum is also blittable.