More Effective C#:改善C#程序的50个具体办法(英文版)(图灵程序设计丛书 微软技术系列)

分類: 图书,计算机与互联网,程序语言与软件开发,语言与开发工具,C语言及其相关,
品牌: 瓦格纳(Bill Wagner)
基本信息·出版社:人民邮电出版社
·页码:297 页
·出版日期:2009年11月
·ISBN:9787115215109
·条形码:9787115215109
·版本:第1版
·装帧:平装
·开本:16
·正文语种:中文/英语
·丛书名:图灵程序设计丛书 微软技术系列
产品信息有问题吗?请帮我们更新产品信息。
内容简介《More Effective C#:改善C#程序的50个具体办法(英文版)》针对C# 2.0和3.0中添加的新特性给出了改善C#代码的50条实用建议,其中着重介绍了泛型技术,这是C# 2.0和3.0中众多新特性的基石。《More Effective C#:改善C#程序的50个具体办法(英文版)》按照建议的主题进行分类,其中每个建议针对某个特定问题进行展开,分析了问题的原因,给出解决的办法。
《More Effective C#:改善C#程序的50个具体办法(英文版)》适合各层次.NET开发人员阅读。
作者简介Bill Wagner是世界知名的.NET专家,微软CO领域的MVP,并荣获微软Regional Director称号。他是著名软件咨询公司SRT Solutions的创始人,有20多年软件开发经验,曾经领导了众多成功的Windows平台产品的开发。他是微软开发社区的活跃人物,长期担任MSDN Magazine、ASP.NET Pro、Visual Studio Magazine等技术杂志的专栏作者。
他的blog是http://www.srtsolutions.com/public/blog/20574,可以通过wwagner@SRTSolutions.com与他联系。
媒体推荐“作为C#设计组的成员,很少有书能够让我从中学到什么新东西,本书则是个例外,它很好地将特定的代码和深入的分析结合了起来。……这些富有洞察力的、充满远见的内容会对你日后学习C#提供很大的启发和帮助。”
——Mads Torgersen,微软公司Visual C#项目经理
“Bill Wagner为C#开发人员撰写了一部精彩绝伦的图书,其中介绍了大量C#最佳实践。……若想成为C#开发的顶级高手,那么没有什么资料比Bill Wagner的这本书更好了。Bill非常智慧、深刻,富有经验和技巧。若能将这本书中给出的建议应用到你的代码中,定会大大提高你的工作质量。”
——Charlie Calvert,微软公司Visual C#社区项目经理
编辑推荐《More Effective C#:改善C#程序的50个具体办法(英文版)》:英文原文让你和世界知名.NET专家,微软C#MVP Bill Wagner零距离接触,并肩思考和工作
50个具体办法助你编出优雅的C#程序
针对C#2.0和C#3.0中添加的新特性给出实用建议,着重介绍泛型技术,讨论如何使用C#3.0及LINQ查询语法
深入分析示例代码让你快速领悟其中含义,快速应用到你的开发中
C#语言已经成为目前功能最强大的通用语言之一,近几年的几次升级更是令C#编程世界发生了极大的改变。《More Effective C#:改善C#程序的50个具体办法(英文版)》是Effective C#的续作,秉承了Effective经典系列的卓越风格,用真实的代码示例,通过清晰、贴近实际和简明的阐述,以条目形式为广大程序员提供了凝聚业界经验结晶的专家建议。
《More Effective C#:改善C#程序的50个具体办法(英文版)》中,著名.NET专家Bill Waqner围绕C#2.0和3.O中的新特性给出了实用的建议,涉及泛型、多线程编程、设计实践、C#3.0语言增强、LlNQ、可空类型等主题,讲述了如何在开发中使用这些新语言特性,如何避免误用所造成的影响。书中每个条目自成一体,针对使用C#时的某个特定问题,帮助你以最佳的方式切换至C#3 O。通过阅读《More Effective C#:改善C#程序的50个具体办法(英文版)》,读者完全可以举一反三,将其中许多建议应用到自己的日常编程工作中。
C#语言顶级高手的秘籍
业界资深专家智慧和经验的结晶
理论和实践的完美结合
目录
Chapter 1. Working with Generics 4
Item 1. Use Generic Replacements of 1.x Framework API Classes 4
Item 2. Define Constraints That Are Minimal and Sufficient 14
Item 3. Specialize Generic Algorithms Using Runtime Type Checking 19
Item 4. Use Generics to Force Compile-Time Type Inference 26
Item 5. Ensure That Your Generic Classes Support Disposable Type Parameters 32
Item 6. Use Delegates to Define Method Constraints on Type Parameters 36
Item 7. Do Not Create Generic Specialization on Base Classes or Interfaces 42
Item 8. Prefer Generic Methods Unless Type Parameters Are Instance Fields 46
Item 9. Prefer Generic Tuples to Output and Ref Parameters 50
Item 10. Implement Classic Interfaces in Addition to Generic Interfaces 56
Chapter 2. Multithreading in C# 63
Item 11. Use the Thread Pool Instead of Creating Threads 67
Item 12. Use BackgroundWorker for Cross-Thread Communication 74
Item 13. Use lock() as Your First Choice for Synchronization 78
Item 14. Use the Smallest Possible Scope for Lock Handles 86
Item 15. Avoid Calling Unknown Code in Locked Sections 90
Item 16. Understand Cross-Thread Calls in Windows Forms and WPF 93
Chapter 3. C# Design Practices 105
Item 17. Create Composable APIs for Sequences 105
Item 18. Decouple Iterations from Actions, Predicates, and Functions 112
Item 19. Generate Sequence Items as Requested 117
Item 20. Loosen Coupling by Using Function Parameters 120
Item 21. Create Method Groups That Are Clear, Minimal, and Complete 127
Item 22. Prefer Defining Methods to Overloading Operators 134
Item 23. Understand How Events Increase Runtime Coupling Among Objects 137
Item 24. Declare Only Nonvirtual Events 139
Item 25. Use Exceptions to Report Method Contract Failures 146
Item 26. Ensure That Properties Behave Like Data 150
Item 27. Distinguish Between Inheritance and Composition 156
Chapter 4. C# 3.0 Language Enhancements 163
Item 28. Augment Minimal Interface Contracts with Extension Methods 163
Item 29. Enhance Constructed Types with Extension Methods 167
Item 30. Prefer Implicitly Typed Local Variables 169
Item 31. Limit Type Scope by Using Anonymous Types 176
Item 32. Create Composable APIs for External Components 180
Item 33. Avoid Modifying Bound Variables 185
Item 34. Define Local Functions on Anonymous Types 191
Item 35. Never Overload Extension Methods 196
Chapter 5. Working with LINQ 201
Item 36. Understand How Query Expressions Map to Method Calls 201
Item 37. Prefer Lazy Evaluation Queries 213
Item 38. Prefer Lambda Expressions to Methods 218
Item 39. Avoid Throwing Exceptions in Functions and Actions 222
Item 40. Distinguish Early from Deferred Execution 225
Item 41. Avoid Capturing Expensive Resources 229
Item 42. Distinguish Between IEnumerable and IQueryable Data Sources 242
Item 43. Use Single() and First() to Enforce Semantic Expectations on Queries 247
Item 44. Prefer Storing Expressionto Func249
Chapter 6. Miscellaneous 255
Item 45. Minimize the Visibility of Nullable Values 255
Item 46. Give Partial Classes Partial Methods for Constructors, Mutators, and Event Handlers 261
Item 47. Limit Array Parameters to Params Arrays 266
Item 48. Avoid Calling Virtual Functions in Constructors 271
Item 49. Consider Weak References for Large Objects 274
Item 50. Prefer Implicit Properties for Mutable, Nonserializable Data 277
Index 283
……[看更多目录]
序言自从 Anders Hejlsberg在 2005年专业开发者大会上第一次演示 LINQ(Language-Integrated Query,语言集成查询)以来,C#编程世界被彻底地改变了,LINQ的出现为 C#语言带来了几个令人着迷的新特性:扩展方法,局部变量类型推断,lambda表达式,匿名类型,对象初始化器以及集合初始化器,C# 2.0也为 LINQ的出现打下了坚实的基础,添加了包括泛型,迭代器,静态类,可空类型,属性访问器权限以及匿名委托等新功能,即使在非 LINQ的使用环境中,这些语言特性也有大显身手之处 ——毕竟还有很多非数据访问的编程任务。
本书针对 C# 2.0和 C#3.0中添加的新特性给出了实用的建议,也包含了我在上本图书 Effective C#: 50 Specific Ways to Improve Your C#(Addison-Wesley, 2004)中没有提到的高级特性,本书中的条目主要针对那些正在使用 C# 3.0编写程序的开发人员,书中着重介绍了泛型技术,这是 C# 2.0和 C# 3.0中众多新特性的基石,本书中的条目并没有按照语言特性组织,而是根据新特性最善于解决的编程问题来编排的,与 Effective Software Development丛书中的其他图书一样,本书中每个条目的建议都自成一体,针对使用 C#时的某个特定问题,这些条目能够帮助你以最佳的方式从 C# 1,x切换至 C# 3.0。
泛型是 C#3.0中所有新特性的基础,虽然只有第 1章专门介绍了泛型,但你会发现泛型技术也几乎是每个条目中不可分割的一部分,阅读本书之后,你定会熟悉并喜欢上泛型以及元编程(metaprogramming)概念,
当然,本书中的很大一部分篇幅都用来讨论了如何使用 C# 3.0以及 LINQ查询语法,不过不管你是否将其用在查询数据源上,C# 3.0所添加的众多语言新特性均非常有用,语言上的改变非常巨大,LINQ又是引起改变的主要原因,它们都需要专门的章进行介绍,LINQ和 C# 3.0将深刻影响你编写 C#代码的方式,而本书则会让这个过渡更加平稳简单。
文摘插图:

Without a doubt, C# 2.0 added a feature that continues to have a big impact on how you write C# code: generics. Many articles and papers have been written about the advantages of using generics over the previous ver- sions of the C# collections classes, and those articles are correct. You gain compile-time type safety and improve your applications' performance by using generic types rather than weakly typed collections that rely on System. Object.
Some articles and papers might lead you to believe that generics are use- ful only in the context of collections. That's not true. There are many other ways to use generics. You can use them to create interfaces, event handlers, common algorithms, and more.
Many other discussions compare C# generics to C++ templates, usually to advocate one as better than the other. Comparing C# generics to C++ templates is useful to help you understand the syntax, but that's where the comparison should end. Certain idioms are more natural to C++ tem- plates, and others are more natural to C# generics. But, as you'll see in Item 2 a bit later in this chapter, trying to decide which is"better" will only hurt your understanding of both of them. Adding generics required changes to the C# compiler, the Just In Time (JlT) compiler, and the Common Lan- guage Runtime (CLR). The C# compiler takes your C# code and creates the Microsoft Intermediate Language (MSIL, or IL) definition for the generic type. In contrast, the JIT compiler combines a generic type definition with a set of type parameters to create a closed generic type. The CLR supports both those concepts at runtime.
There are costs and benefits associated with generic type definitions. Sometimes, replacing specific code with a generic equivalent makes your program smaller. At other times, it makes it larger. Whether or not you encounter this generic code bloat depends on the specific type parameters
……[看更多书摘]