码迷,mamicode.com
首页 > Windows程序 > 详细

C# - readonly

时间:2014-11-25 16:38:19      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:readonly   c#   

The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.

The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore,readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants.

C# - readonly

标签:readonly   c#   

原文地址:http://blog.csdn.net/troubleshooter/article/details/41481077

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!