C#试题(三)Const和Readonly的区别
- const 属性是在编译时初始化,而readonly属性是在运行时初始化。
1
.method private hidebysig static void Main(string[] args) cil managed
2
{
3
.entrypoint
4
// Code size 24 (0x18)
5
.maxstack 8
6
IL_0000: nop
7
IL_0001: ldstr "World"
8
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
9
IL_000b: nop
10
IL_000c: ldsfld string [ConstLibrary]ConstLibrary.Class1::country
11
IL_0011: call void [mscorlib]System.Console::WriteLine(string)
12
IL_0016: nop
13
IL_0017: ret
14
} // end of method MyClass::Main
15
.method private hidebysig static void Main(string[] args) cil managed2
{3
.entrypoint4
// Code size 24 (0x18)5
.maxstack 86
IL_0000: nop7
IL_0001: ldstr "World"8
IL_0006: call void [mscorlib]System.Console::WriteLine(string)9
IL_000b: nop10
IL_000c: ldsfld string [ConstLibrary]ConstLibrary.Class1::country11
IL_0011: call void [mscorlib]System.Console::WriteLine(string)12
IL_0016: nop13
IL_0017: ret14
} // end of method MyClass::Main15




浙公网安备 33010602011771号