gpt4 book ai didi

c# - 枚举的低级表示

转载 作者:太空宇宙 更新时间:2023-11-03 19:54:31 24 4
gpt4 key购买 nike

我有这个枚举:

enum Color
{
RED,
GREEN,
BLUE
}

以及以下 IL 生成的代码:

.class private auto ansi sealed WindowsFormsApplication1.Color
extends [mscorlib]System.Enum
{
// Fields
.field public specialname rtspecialname int32 value__
.field public static literal valuetype WindowsFormsApplication1.Color RED = int32(0)
.field public static literal valuetype WindowsFormsApplication1.Color GREEN = int32(1)
.field public static literal valuetype WindowsFormsApplication1.Color BLUE = int32(2)

}

但是我的反编译工具无法显示 C# 反编译代码。

我想知道枚举到底是什么:它是类类型吗?它是结构类型吗?

.class 是什么意思?和 int32(0) 等。

最佳答案

枚举的实际数据类型可以是a number of basic types, like byte, int and long . (在本例中是一个 int:int32 value__)

定义的 .class 包含可能枚举值的支持列表(static 字段和枚举值本身。(注意 .classalso used for struct in CIL ,所以不要太字面地理解它)所以我猜它是一个结构,这更有意义,因为它实际上只包含一个不可变的支持字段。它被视为一种基本类型。

int32(0) 创建一个值为 0 的整数,这是枚举中第一项的默认值。

关于c# - 枚举的低级表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35339933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com