导语
内容提要
在比尔·瓦格纳著的《Effective C#(编写高质量C#代码的50条有效方法第3版英文版)/原味精品书系》中,.NET专家Bill Wagner为我们提供了50条有效的方法,通过这些方法可以利用C#的全部语言功能编写健壮、高效和运行良好的代码。Wagner利用他杰出的C#使用经验,解决了从资源管理到多核支持的各种问题,并揭示了如何规避语言和.NET环境中常见的陷阱。本书主要写给那些把C#当作日常开发工具的专业开发者,读者需要事先熟悉C#语法和语言特性。
作者简介
比尔·瓦格纳(Bill Wagner),世界知名的C#专家,也是ECMA C#标准委员会成员。他在Humanitarian Toolbox项目中担任主管,并荣获微软公司.NET MVP称号长达11年,最近开始在.NET Foundation AdvisoryCouncil任职。Wagner在工作中与各种规模的公司合作,帮助这些创业公司或企业改进软件开发流程,并培养软件开发团队。目前,他是微软.NET核心内容团队的员工,写过很多与C#语言及.NET框架有关的学习资料。他拥有伊利诺伊大学厄巴纳-尚佩恩分校计算机科学专业的学士学位。
目录
Chapter 1 C# Language Idioms
Item1: Prefer Implicitly Typed Local Variables
Item2: Prefer readonly to const
Item3: Prefer the is or as Operators to Casts
Item4: Replace string.Format() with Interpolated Strings
Item5: Prefer FormattableString for Culture-Specific Strings
Item6: Avoid String-ly Typed APIs
Item7: Express Callbacks with Delegates
Item8: Use the Null Conditional Operator for Event Invocations
Item9: Minimize Boxing and Unboxing
Item10: Use the new Modifier Only to React to Base Class Updates
Chapter 2 .NET Resource Management
Item11: Understand .NET Resource Management
Item12: Prefer Member Initializers to Assignment Statements
Item13: Use Proper Initialization for Static Class Members
Item14: Minimize Duplicate Initialization Logic
Item15: Avoid Creating Unnecessary Objects
Item16: Never Call Virtual Functions in Constructors
Item17: Implement the Standard Dispose Pattern
Chapter 3 Working with Generics
Item18: Always Define Constraints That Are Minimal and Sufficient
Item19: Specialize Generic Algorithms Using Runtime Type Checking
Item20: Implement Ordering Relations with IComparable<T> and IComparer<T>
Item21: Always Create Generic Classes That Support Disposable Type Parame
Item22: Support Generic Covariance and Contravariance
Item23: Use Delegates to Define Method Constraints on Type Parameters
Item24: Do Not Create Generic Specialization on Base Classes or Interfaces
Item25: Prefer Generic Methods Unless Type Parameters Are Instance Fields
Item26: Implement Classic Interfaces in Addition to Generic Interfaces
Item27: Augment Minimal Interface Contracts with Extension Methods
Item28: Consider Enhancing Constructed Types with Extension Methods
Chapter 4 Working with LINQ
Item29: Prefer Iterator Methods to Returning Collections
Item30: Prefer Query Syntax to Loops
Item31: Create Composable APIs for Sequences
Item32: Decouple Iterations from Actions, Predicates, and Functions
Item33: Generate Sequence Items as Requested
Item34: Loosen Coupling by Using Function Parameters
Item35: Never Overload Extension Methods
Item36: Understand How Query Expressions Map to Method Calls
Item37: Prefer Lazy Evaluation to Eager Evaluation in Queries
Item38: Prefer Lambda Expressions to Methods
Item39: Avoid Throwing Exceptions in Functions and Actions
Item40: Distinguish Early from Deferred Execution
Item41: Avoid Capturing Expensive Resources
Item42: Distinguish between IEnumerable and IQueryable Data Sources
Item43: Use Single() and First() to Enforce Semantic Expectations on Queries
Item44: Avoid Modifying Bound Variables
Chapter 5 Exception Practices
Item45: Use Exceptions to Report Method Contract Failures
Item46: Utilize using and try/finally for Resource Cleanup
Item47: Create Complete Application-Specific Exception Classes
Item48: Prefer the Strong Exception Guarantee
Item49: Prefer Exception Filters to catch and re-throw
Item50: Leverage Side Effects in Exception Filters
Index