人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 15, 2006

C#的const和readonly

Filed under: C#

–相同

const和readonly的值一旦初始化则都不再可以改写.

–不同

    const只能在声明时初始化;readonly既可以在声明时初始化也可以在构造器中初始化;
    const隐含static,不可以再写static const;readonly则不默认static,如需要可以写static readonly;
    const是编译期静态解析的常量(因此其表达式必须在编译时就可以求值);readonly则是运行期动态解析的常量;
    const既可用来修饰类中的成员,也可修饰函数体内的局部变量;readonly只可以用于修饰类中的成员

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/05/15/p26/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham