CLR Via C# 3rd 阅读摘要 -- Chapter 7 - Constants and Fileds
2010-03-19 15:47
796 查看
Constants
1. 能用做常量的类型:Boolean,Char,Byte,SByte,Int16,UInt16,Int32,UInt32,Int64,UInt64,Single,Double,Decimal,String;2. 如果一个程序集中定义的常量改变了,那么在程序集编译之后,使用该程序集的应用程序也需要重新编译才能生效。
Fields
1. 字段修改符:Static(static), Instance((default)), InitOnly(readonly), Volatile(volatile) ;2. static readonly替代const,当程序集中定义的 静态只读字段修改之后,只需要编译该程序集发布,那些使用该程序集的应用程序不需要重新编译;
3. 上面那条的理论基础是:新版本的DLL程序集不是强名称的;
4. 一个引用类型的字段如果标记为readonly,那么这个引用是不可变的,但不代表这个字段引用的对象也是不可变的。
本章小结
这章的内容比较简单,主要就是说明了const和static readonly的特征和区别。相关文章推荐
- CLR Via C# 3rd 阅读摘要 -- Chapter 6 - Type and Member Basics
- CLR Via C# 3rd 阅读摘要 -- Chapter 22 – CLR Hosting and AppDomains
- CLR Via C# 3rd 阅读摘要 -- Chapter 3 - Shared Assemblies and Strongly Named Assemblies
- CLR Via C# 3rd 阅读摘要 -- Chapter 15 - Enumerated Types and Bit Flags
- CLR Via C# 3rd 阅读摘要 -- Chapter 23 – Assembly Loading and Reflection
- CLR Via C# 3rd 阅读摘要 -- Chapter 5 - Primitive, Reference, and Value Types
- CLR Via C# 3rd 阅读摘要 -- Chapter 14 - Chars, Strings, and Working with Text
- CLR Via C# 3rd 阅读摘要 -- Chapter 2 - Building, Packaging, Deploying, and Administering Applications and Types
- CLR Via C# 3rd 阅读摘要 -- Chapter 20 – Exceptions and State Management
- CLR Via C# 3rd 阅读摘要 -- Chapter 19 – Nullable Value Types
- CLR Via C# 3rd 阅读摘要 -- Chapter 8 - Methods
- CLR Via C# 3rd 阅读摘要 -- Chapter 1 - The CLR's Execution Model
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- CLR Via C# 3rd 阅读摘要 -- Chapter 4 - Type Fundamentals
- CLR Via C# 3rd 阅读摘要 -- Chapter 16 - Arrays
- CLR Via C# 3rd 阅读摘要 -- Chapter 18 - Custom Attributes
- CLR Via C# 3rd 阅读摘要 -- Chapter 11 - Events
- CLR Via C# 3rd 阅读摘要 -- Chapter 13 - Interfaces
- CLR Via C# 3rd 阅读摘要 -- Chapter 12 - Generics
- CLR Via C# 3rd 阅读摘要 -- Chapter 9 - Parameters