More Effective C#: 50 Specific Ways to Improve Your C#

Front Cover
Pearson Education, Oct 1, 2008 - Computers - 336 pages

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.

 

What people are saying - Write a review

We haven't found any reviews in the usual places.

Contents

Contents at a Glance Introduction
Define Constraints That Are Minimal and Sufficient
Use Generics to Force CompileTime Type Inference
Do Not Create Generic Specialization on Base Classes
Implement Classic Interfaces in Addition to Generic
Use the Thread Pool Instead of Creating Threads
Use BackgroundWorker for CrossThread Communication
Use lock as Your First Choice for Synchronization
Enhance Constructed Types with Extension Methods
Prefer Implicitly Typed Local Variables
Limit Type Scope by Using Anonymous Types
Create Composable APIs for External Components
Avoid Modifying Bound Variables
Define Local Functions on Anonymous Types
Never Overload Extension Methods
Understand How Query Expressions Map to Method Calls

Use the Smallest Possible Scope for Lock Handles
Avoid Calling Unknown Code in Locked Sections
Understand CrossThread Calls in Windows Forms and
Create Composable APIs for Sequences
Decouple Iterations from Actions Predicates and Functions
Generate Sequence Items as Requested
Loosen Coupling by Using Function Parameters
Create Method Groups That Are Clear Minimal and Complete
Prefer Defining Methods to Overloading Operators
Understand How Events Increase Runtime Coupling Among Objects
Declare Only Nonvirtual Events
Use Exceptions to Report Method Contract Failures
Ensure That Properties Behave Like Data
Distinguish Between Inheritance and Composition
Augment Minimal Interface Contracts with Extension Methods
Prefer Lazy Evaluation Queries
Prefer Lambda Expressions to Methods
Avoid Throwing Exceptions in Functions and Actions
Distinguish Early from Deferred Execution
Avoid Capturing Expensive Resources
Distinguish Between IEnumerable and IQueryable Data Sources
Use Single and First to Enforce Semantic Expectations on Queries
Prefer Storing Expression to Func
Minimize the Visibility of Nullable Values
Give Partial Classes Partial Methods for Constructors Mutators and Event Handlers
Limit Array Parameters to Params Arrays
Avoid Calling Virtual Functions in Constructors
Consider Weak References for Large Objects
Prefer Implicit Properties for Mutable Nonserializable Data
Working with Generics Chapter 2 Multithreading in

Other editions - View all

Common terms and phrases

About the author (2008)

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).

Bibliographic information