Chinaunix首页 | 论坛 | 博客
  • 博客访问: 107689
  • 博文数量: 20
  • 博客积分: 1910
  • 博客等级: 上尉
  • 技术积分: 485
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-10 15:46
文章分类

全部博文(20)

文章存档

2013年(3)

2012年(4)

2011年(10)

2010年(1)

2009年(2)

我的朋友

分类:

2009-11-02 15:52:07

 

To define a constant field, simply apply the const modifier and initialize it to some value.  A constant field must be initialized to another constant value, either a literal or a constant variable. Of course, once initialized, a constant field value can never change.

 

The compiler handles constants by "hard coding" the value into the CIL(Common Intermediate Language, it is also referred to IL or MSIL). Also note that constant members are implicitly static.

 

Use the readonly modifier to define a field that need to be initialized with a non-constant value but must never change after initialization. 

 

The value of a readonly field is determined dynamically at runtime. In contrast, the value of a constant field is hardcoded into the CIL at compile time.

Readonly fields are instance fields, whereas constant fields are implicitly static.

 

阅读(430) | 评论(0) | 转发(0) |
0

上一篇:abstract vs interface

下一篇:Convert String to Type

给主人留下些什么吧!~~