More Effective C#: 50 Specific Ways to Improve Your C#
- By Bill Wagner
- Published Oct 7, 2008 by Addison-Wesley Professional. Part of the Effective Software Development Series series.
- Copyright 2009
- Dimensions: 7x9-1/4
- Pages: 336
- Edition: 1st
- ISBN-10: 0-321-48589-0
- ISBN-13: 978-0-321-48589-2
Register your product to gain access to bonus material or receive a coupon.
Product Author Bios
Bill Wagner, cofounder of SRT Solutions, has developed commercial software for more than twenty years and led design for many successful engineering and enterprise Microsoft Windows products. He has been a Microsoft Regional Director since 2003 and a Microsoft MVP for C# since 2005. Wagner consults routinely with the C# team on new features for forthcoming versions of C#. He has a regular column in Visual Studio Magazine and speaks frequently at conferences and user groups. His tutorials and advanced essays have appeared in MSDN Magazine, MSDN Online, .NET Insight, .NET DJ, and the MSDN C# Team Developer Center. Wagner is also the author of the best-selling Effective C# (Addison-Wesley, 2005).
“Shining a bright light into many of the dark corners of C# 3.0, this book not only covers the ‘how,’ but also the ‘why,’ arming the reader with many field-tested methods for wringing the most from the new language features, such as LINQ, generics, and multithreading. If you are serious about developing with the C# language, you need this book.”
–Bill Craun, Principal Consultant, Ambassador Solutions, Inc.
“More Effective C# is an opportunity to work beside Bill Wagner. Bill leverages his knowledge of C# and distills his expertise down to some very real advice about programming and designing applications that every serious Visual C# user should know. More Effective C# is one of those rare books that doesn’t just regurgitate syntax, but teaches you how to use the C# language.”
–Peter Ritchie, Microsoft MVP: Visual C#
“More Effective C# is a great follow-up to Bill Wagner’s previous book. The extensive
C# 3.0 and LINQ coverage is extremely timely!”
–Tomas Restrepo, Microsoft MVP: Visual C++, .NET, and Biztalk Server
“As one of the current designers of C#, it is rare that I learn something new about the language by reading a book. More Effective C# is a notable exception. Gently blending concrete code and deep insights, Bill Wagner frequently makes me look at C# in a fresh light–one that really makes it shine. More Effective C# is at the surface a collection of very useful guidelines. Look again. As you read through it, you’ll find that you acquire more than just the individual pieces of advice; gradually you’ll pick up on an approach to programming in C# that is thoughtful, beautiful, and deeply pleasant. While you can make your way willy-nilly through the individual guidelines, I do recommend reading the whole book–or at least not skipping over the chapter introductions before you dive into specific nuggets of advice. There’s perspective and insight to be found there that in itself can be an important guide and inspiration for your future adventures in C#.”
–Mads Torgersen, Program Manager, Visual C#, Microsoft
“Bill Wagner has written an excellent book outlining the best practices for developers who work with the C# language. By authoring More Effective C#, he has again established himself as one of the most important voices in the C# community. Many of us already know how to use C#. What we need is advice on how to hone our skills so that we can become wiser programmers. There is no more sophisticated source of information on how to become a first-class C# developer than Bill Wagner’s book. Bill is intelligent, thoughtful, experienced, and skillful. By applying the lessons from this book to your own code, you will find many ways to polish and improve the work that you produce.”
–Charlie Calvert, Community Program Manager, Visual C#, Microsoft
In More Effective C#, Microsoft C# MVP and Regional Director Bill Wagner introduces fifty brand-new ways to write more efficient and more robust software. This all-new book follows the same format as Wagner’s best-selling Effective C# (Addison-Wesley, 2005), providing clear, practical explanations, expert tips, and plenty of realistic code examples.
Wagner shows how to make the most of powerful innovations built into Microsoft’s new C# 3.0 and .NET Framework 3.5, as well as advanced C# language capabilities not covered in his previous book. Drawing on his unsurpassed C# experience, the author reveals new best practices for working with LINQ, generics, metaprogramming, and many other features. He also uncovers practices that compromise performance or reliability and shows exactly how to avoid them.
More Effective C# shows how to
- Use generics to express your design intent more effectively
- Master advanced generics techniques, such as constraints, method constraints, and generic specialization
- Use the multithreaded techniques you’ll need to work with the .NET framework every day
- Express modern design idioms using the rich palette of C# language features
- Successfully mix object oriented and functional programming constructs
- Create composable interfaces and avoid confusion in public interfaces
- Use extension methods to separate contracts from implementation
- Program successfully with C# closures and anonymous types
- Write more effective LINQ queries
- Make the most of LINQ Lazy Evaluation Queries and Lambda Expressions
- Distinguish and convert between delegates and expression trees
- Efficiently utilize nullable types and partial classes
- Use implicit properties for mutable, nonserializable data
You’re already a successful C# programmer–this book can help you become an outstanding one.
12 of 12 people found the following review helpful
A book of magic tricks,
This review is from: More Effective C#: 50 Specific Ways to Improve Your C# (Paperback)I've been waiting on this book for ages. Mr. Wagner's original "Effective C#" was a revelation to me. He raised questions I never thought to ask myself about why we do things certain ways in C# rather than others, and then provided insights into what the stakes were. Reading "Effective C#" basically taught me to take programming seriously. I learned to always question my own decisions and to look for better ways to do what I already knew how to do moderately well.
The only shortcoming of "Effective C#" was that it was written for the 1.1 framework, and new editions were never forthcoming. I assumed that Mr. Wagner was spending all these intervening silent years updating his original book.
With "More Effective C#" however, we actually get something quite different. Of course, there are plenty of chapters detailing the post-1.1 features of the C# language, and these are extremely valuable. For instance, the first chapter in this new book is a fresh take on... Read more
6 of 6 people found the following review helpful
Another great book by Bill Wagner,
This review is from: More Effective C#: 50 Specific Ways to Improve Your C# (Paperback)"More Effective C#" continues in the same style as Bill's first book, "Effective C#": short, concise articles around a specific topic you'll need to pay attention to when figuring out how to write the best C# code you possibly can.
Bill starts off with a deep dive into Generics and some of the many subtleties you need to consider. He points out things like considering how you write generic code in base classes, genericized algorithms, and working with generic interfaces. Bill moves through other broad categories including LINQ, C# Design, and enhancements in the 3.0 release of C#. There's also a great section on multithreading in C# which hits some great points in this very arcane but critical aspect of development.
This book definitely isn't a tutorial on C#, but I'd say that it's critical for all devs, regardless of experience, to read through. I'd also say, although Bill will likely disagree with me, that many of the tenets he puts forth can apply to folks... Read more
3 of 3 people found the following review helpful
A must read for C# developers,
This review is from: More Effective C#: 50 Specific Ways to Improve Your C# (Paperback)Anyone who is writing C# on a daily basis has to read this book. In 50 very easy to read short modules, Bill shows you how to improve your C# code. I have been coding with C# since 2002 and I learned many new techniques about Generics and the new language features from 3.0. With LINQ, I *finally* know why an implicitly typed local variable is better and the implications of not using IQueryable. A wealth of knowledge. After you read your C# 101 books, read this one next! It will make you a better developer.
› See all 19 customer reviews...
Table of Contents
Chapter 1: Working with Generics 1
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 Expression<> to Func<> 249
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
Book + eBook Bundle
Book Price $43.99
eBook Price $15.40
eBook formats included
This book includes free shipping!
This book includes free shipping!
Includes EPUB, MOBI, and PDF
About eBook Formats
This eBook includes the following formats, accessible from your Account page after purchase:
EPUBThe open industry format known for its reflowable content and usability on supported mobile devices.
MOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.
PDFThe popular standard, used most often with the free Adobe® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.
Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.