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
posted @ 2007-09-20 14:58  许晓光  阅读(219)  评论(0)    收藏  举报