Item 12: Prefer Member Initializers to Assignment Statements(Effective C#)
2011-01-21 23:37
555 查看
Member initializers are the simplest way to ensure that the member variables in your type are initialized regardless of which constructor is called. The initializers are executed before each constructor you make for your type. Using this syntax means that you cannot forget to add the proper initialization when you add new constructors for a future release. Use initializers when all constructors create the member variable the same way; it’s simpler to read and easier to maintain.
相关文章推荐
- Effective C#之12:Prefer Variable Initializers to Assignment Statements
- Item 12:Perfer Variable Initializers to Assignment Statements
- Effective C# Item12: Prefer Variable Initializers to Assignment Statements
- Item 22: Prefer Defining and Implementing Interfaces to Inheritance(Effective C#)
- Item 8: Prefer Query Syntax to Loops(Effective C#)
- Item 30: Prefer Overrides to Event Handlers(Effective C#)
- Effective C#之Item 35:Prefer Overrides to Event Handlers
- Effective C# Item19: Prefer Defining and Implementing Interfaces to Inheritance
- Item 2: Prefer readonly to const(Effective C#)
- Item 3: Prefer the is or as Operators to Casts(Effective C#)
- Effective C#之Item 41:Prefer DataSets to Custom Structures
- [EffectiveC++]item10:have assignment operators return a reference to *this
- Effective C# Item 35: Prefer Overrides to Event Handlers
- Effective C# Item 11: Prefer foreach Loops
- Item 2: 使用readonly代替const(Prefer readonly to const)
- Item 23: Prefer non-member non-friend functions to member functions(Effective C++)
- Effective C#之Item 45:Prefer the Strong Exception Guarantee
- Effective C# Item 5: Always Provide ToString()
- Effective C#之19:Prefer Defining and Implementing Interfaces to Inheritance
- Effective C#之Item 25: Prefer Serializable Types