小编SAI*_*011的帖子

在哪里为静态,常量和只读字段分配内存?

我已经在程序中使用了这三个字段,并在用法上有所不同,但是我对这些字段存储在何处感到有点困惑?在数据段(堆栈还是堆?)或代码段中?

static int a;
const int b=1235;
readonly int c;
Run Code Online (Sandbox Code Playgroud)

在ILDASM中,字段描述如下

对于静态:.field private静态int32 a

对于常量:.field私有静态文字int32 b = int32(0x000004D3)

对于只读:.field private initonly int32 c

c# static constants readonly

5
推荐指数
1
解决办法
217
查看次数

标签 统计

c# ×1

constants ×1

readonly ×1

static ×1