2.为你的常量选择readonly而不是const
2012-10-22 09:17
288 查看
const 在编译时需要确定其值,所以const的字段默认是静态的,因而不能这样声明:static const string str; 因为const 是编译时确定,所以其不能用于带new的类型,只能用于一些简单类型。注const DateTime dt=new DateTime();是错误的。
readonly 是运行时常量,其值在编译时不确定。
readonly 是运行时常量,其值在编译时不确定。
相关文章推荐
- [转]Effective C#原则2:为你的常量选择readonly而不是const
- Effective C# 原则2:为你的常量选择readonly而不是const
- 为你的常量选择readonly而不是const
- EffectiveC#2--为你的常量选择readonly而不是const
- 原则2:为你的常量选择readonly而不是const
- 为你的常量选择readonly而不是const(译,转)
- Effective C# 原则2:为你的常量选择readonly而不是const(译)
- Effective C# 原则2:为你的常量选择readonly而不是const
- Effective C# 原则2:为你的常量选择readonly而不是const[转载]
- Effective C# 原则2:为你的常量选择readonly而不是const(译)
- 为你的常量选择readonly而不是const
- 原则2:为你的常量选择readonly而不是const
- 选择readonly而不是const
- 规则二 对常量使用ReadOnly而不是const
- 【C#高效编程50例】条目2:用运行时常量(readonly)而不是编译期常量(const)
- 创建常量时尽可能使用readonly,而不是const
- C语言为什么被const声明的变量不是一个常量表达式
- Effiective C#:ITEM2:优先使用readonly而不是const
- 使用const而不是宏来定义常量的好处
- C#中的静态常量(const)和动态常量(static和readonly)用法和区别