Essential C# 5.0

Essential C# 5.0 is a well-organized, “no-fluff” guide to the latest versions of C# for programmers at all levels of C# experience.

Fully updated to reflect new features and programming patterns introduced with C# 5.0 and .NET 4.5, this guide shows you how to write C# code that is simple, powerful, robust, secure, and maintainable. Microsoft MVP Mark Michaelis and C# principal developer Eric Lippert provide comprehensive coverage of the entire language, offering a complete foundation for effective software development.

Essential C# 5.0cropped

The authors illustrate key constructs with succinct, downloadable code examples. Graphical mind maps at the beginning of each chapter outline the material that is covered and how individual topics interrelate. This edition also includes C# Coding Guidelines that call attention to today’s best practices for writing C# code. Separate indexes of C# versions 3.0, 4.0, and 5.0 make it easy to find answers specific to whatever version of C# you are using.

Throughout, topics intended for beginners and advanced readers are clearly marked. If you’re new to C#, this guide will help you start writing significant code quickly. If you’re an experienced C# developer, you’ll gain insight into today’s most complex programming challenges and techniques as you master key C# 5.0 innovations such as async/await pattern. No matter how advanced your skills become, you’ll come to rely on this indispensable reference.

Coverage includes:

  • Mastering C# data types, operators, control flow, methods, and parameters
  • Making the most of C# object-oriented constructs, including classes, inheritance, interfaces, and more
  • Building reliable, effective exception handling into your code
  • Using generics, delegates, Lambda expressions, and events to reduce code complexity
  • Learning dynamic programming with reflection and attributes
  • Querying virtually any type of data using LINQ with Query Expressions
  • Creating custom collections that operate against business objects
  • Understanding the Common Language Infrastructure and C# in the context of the .NET 4.5 development platform
  • Taking advantage of declarative programming, embedded metadata, reflection, and attributes
  • Thoroughly mastering multithreading and synchronization, including the new async/await paradigm
  • Discussion of WinRT and programming in C# for Windows 8
  • Using P/Invoke, pointers, and direct memory manipulation to interoperate with code in other languages
  • Understanding how C# programs relate to the underlying runtime

Errata Document


Sample Chapters



“NOTE: this content is taken from the previous edition of Essential C# 3.5, not 4.0.”

Code Listing Source Code

The code is available on GitHub – feel free to make pull requests.


The sample code doesn’t contain every code listing within the book. If there are particular samples missing that you would like to have please email and let me know.

Special thanks to Kody Brown who did a ton of work reviewing, testing, and posting the code for this edition.

About the Authors

MARK MICHAELIS founded IntelliTect and serves as its chief technical architect and trainer. Since 1996, he has been a Microsoft MVP for C#, Visual Studio Team System, and the Windows SDK; in 2007, he was recognized as a Microsoft Regional Director. Michaelis serves on several Microsoft software design review teams, including C#, Connected Systems, Office/SharePoint, and Visual Studio. He speaks at developer conferences and has written many articles and books.

ERIC LIPPERT is a principal developer on the C# compiler team at Microsoft, and a member of the C# language design team. He has worked on the design and implementation of several Microsoft languages, and on Visual Studio Tools for Office.

If you want to be a C# developer, or if you want to enhance your C# programming skills, there is no more useful tool than a well-crafted book on the subject. You are holding such a book in your hands.”

~ From the Foreword by Charlie Calvert, Community Program Manager,
Visual C#, Microsoft

Essential C# 3.0 pulls off a very difficult task. The early chapters are comprehensible by beginning developers, while the later chapters pull no punches and provide the experienced developer with the detailed information they need to make the most of C# 3.0. Starting with the first chapter, Mark has successfully interwoven tidbits of information useful to even the most advanced developer while keeping the book approachable.”

~ Chris Kinsman, chief architect, Vertafore, Microsoft Regional Director

How refreshing! This book deals with C# thoroughly, rather than skimming over the whole .NET framework. It is valuable to newcomers and professionals alike.”

~ Jon Skeet, C# MVP

Essential C# 3.0 is a one-stop shop for an experienced programmer looking to ramp up on one of the hottest languages around today. Mark delivers an intelligent and detailed tour of C#, providing newcomers to the language with a solid foundation of skill on which to build their next generation of applications.”

~ Stephen Toub, technical editor, MSDN Magazine

This book provides complete, up-to-date coverage of all the programming constructs in C#. Masterfully organized, it allows beginning programmers to get on board and leads more experienced programmers into the world of structured programming. Because of its unwavering focus on the essential programming constructs of C# – such as generics, delegates, and much more – this book is indispensable. For programmers who want to solve their day-to-day programming issues using the latest features this modern programming language has to offer, this book is indispensable.”

~ Narendra Poflee, IT integration specialist, Itron Inc.

Essential C# 3.0 is a one-stop shop for an experienced programmer looking to ramp up on one of the hottest languages around today. Mark delivers an intelligent and detailed tour of C#, providing newcomers to the language with a solid foundation of skill on which to build their next generation of applications.”

~ Michael Stokesbary, software engineer, Itron Inc.


  • Derrick Harrison says:

    Greetings from Calgary

    I did a download of your file and it unpipped OK but Appendix B (what I really wanted) did not contain the source code. Am I doing something wrong?

    Also I have noticed a few typos but I could not find any errata listing. Did I miss it?


    Derrick Harrison.

  • Juan Zamudio says:

    Chapter 1, page 26 in the table says “C# 4.0 with .NET Framework 3.5 (visual Studio 2010)”, it should say Framework 4, I can’t believe that’s not in the errata.

  • Geovanny Hernandez says:

    Thank for this excellent book, I´m from Nicaragua, Sorry by my English, Gracias Mark :-)

  • Doug says:

    Page 703 states “… the multithreading chapters from the preceding edition of this book (Essential C# 3.5) are available for download … ” from this web page. So, where’s the link to download them?

  • Pavel Matuška says:

    Page 71:

    “// Retrieve 3rd item in languages array (Java)
    string language = languages[4];”

    I believe it either should be
    string language = languages[2]; (for 3rd)


    // Retrieve 5th item in languages array (Java)
    string language = languages[4];

    as the text says.

  • cai says:

    i found a typo error in page 224
    it should be “class Program” instead of “class Profgram”

  • Steve says:

    Page 435 says “Listing 11.1 included a …” when I believe it meant “Listing 11.11″

  • Harsh says:

    Page 522, Line 4 in Paragraph 1 mentions “OnTemperatureHandler delegate” where I believe it should be “TemperatureChangeHandler delegate” // same thing in Line 1 of 2nd paragraph.

  • Harsh says:

    Page 628, paragraph 2, Line 5 has it as “On a System.Collections.Sorted sorted list” // should be “On a System.Collections.SortedList list”

  • Harsh says:

    Page 600, Line 3 under the section “The Let Clause”, it mentions “the groupby clause in Listing 15.8″ // since there is no such clause in this listing I assume author means “the orderby clause”.

  • Harsh says:

    Page 458, the 2nd code snippet(while explaining contravariance) shows the example as ” Pair contacts = (IPair) pdaPair;” // should be “Pair contacts = (IPair) pdaPair;”

  • Harsh says:

    sorry, in the above post angles got removed. Anyway on Page 458 I think the 2nd code snippet should be Pair #Contact# contacts = (IPair#PdaItem#) pdaPair;

  • Harsh says:

    *correction* Pair #Contact# contacts = (IPair#Contact#) pdaPair;

  • Harsh says:

    Page 256, line 4 under the section ‘Extension Methods’ says DirectoryInfo.Move() where I believe it should be DirectoryInfo.MoveTo() //same thing on last line of the page

  • Norton says:

    Looks like the author didn’t publish his email address, so I thought I would post my question here.
    I downloaded the source code and tried with the Chapter11 listing 11.02. Just was curious if the samples work, and this first sample doesn’t work. Looks like I had to add static Main() in the Program.cs to be able to call Sketch(), from LaunchMain(). But the Sketch() doesn’t do anything other than moving cursor to the right. Looks like the Console input buffer needs to be set properly. Is there something that I am missing, or this is how it is going to be throughout the book? It is disappointing that I paid for the book, and now I have to spend time trying to setup samples.

  • Javier says:


    (Kindle Edition, reading on Kindle Cloud Reader)

    In chapter 6, right before Listing 6.11, one can read:

    Overloading a member causes the runtime to call the most derived implementation (see Listing 6.11).

    It should read:

    Overriding a method causes the runtime to call the most derived implementation (see Listinhg 6.11).

  • JayGregg100 says:

    Softcover, 3rd edition

    Chapter 11, pg 434, Listing 11.11 shows:

    public Pair(T first, T second)
    _Second = second;
    _Second = second;

    It should read:
    public Pair(T first, T second)
    _First = first;
    _Second = second;

  • Melania says:

    This is FANTASIC!!!

  • Richard Leyton says:

    Hello from Van Nuys, California.

    I am enjoying your book Essential C# 5.0. It is very clear and easy to follow. I especially like the Guidelines and the Language Contrast. Showing the Beginning Topic and Advanced Topic is useful also.

    I found an error on P. 100 Listing 3.18: Comparing the Prefix and Postfix Increment Operators.
    The following is the code from the textbook with additional comments added for clarity.

    // Tested and debugged on 1/24/2013 by
    // :: Rich Leyton
    // :: Specializing in C# .NET software development, I help companies develop
    // :: leading edge software solutions across multiple platforms and languages.
    // This program yields the following output:
    // 123, 124, 125
    // 126, 127, 127

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace IncrementExample
    class IncrementExample
    static void Main()
    int x = 123;
    // Displays 123, 124, 125.
    System.Console.WriteLine(“{0}, {1}, {2}”, x++, x++, x);
    // x now contains the value 125.
    // Textbook says Displays 126, 127, 128.
    // It actually displays 126, 127, 127.
    System.Console.WriteLine(“{0}, {1}, {2}”, ++x, ++x, x);
    // Text book says x now contains the value 128.
    // It actually contains 127


    I hope this is helpful.

    Rich Leyton
    :: Specializing in C# .NET software development, I help companies develop
    :: leading edge software solutions across multiple platforms and languages.

  • Richard Leyton says:

    Regarding my comment, would you like me to upload a picture?


    Rich Leyton

  • Rob says:

    I had very high hopes for this book, both to use as a reference, and to help me upgrade my c# knowledge from 4.0 to 5.0.

    The first thing I did after receiving the book was open the index, as I wanted to see what the book had to say about some of my favourite topics.

    To my complete surprise and dismay, the index to this book is completely unusable. There are so many nested levels in the index, and nothing of any kind letting you know where you are, it’s completely impossible to navigate. Most indexes separate the topics by letter (e.g. “A” topics, “B” topics, etc. all the way to “Z”). Nothing like this exists, and I couldn’t find what I was looking for in anything close to a reasonable amount of time.

    I guess I’ll switch back to the C# In A Nutshell series – I should never have moved away from that.

  • Oliver says:

    Errata (First printing, November 2012)
    Chapter 16, page 651
    Requirements of Equality Comparisons:

    … there must be two unequal items that have the same hash code because there are only 232 possible hash codes, …

    I think there are little more then 232 hash codes. Indeed there are 4,294,967,295 possible hash codes (range of Int32).

  • Rusty says:

    Errata: Essential C# 5.0, First Printing, p. 100:

    The comments in Listing 3.18 should indicate that the final value of “x” is 127, not 128. Similarly, Output 3.12 should also reflect a final value of 127.

  • jaysan says:

    First printing November 2012 edition :
    All chapter 3 pages missing the “3” in the top header of the pages saying “Chapter : Operators and Control Flow”
    It should be : “Chapter 3 : Operators and Control Flow”

  • jaysan says:

    First printing November 2012 edition :
    Page 100, the listing 3.18 says in the comments :
    “// x now contains the value 128.”
    It should be :
    “// x now contains the value 127.”

    Then the output 3.12 says :
    “126, 127, 128″
    It should be :
    “126, 127, 127″

  • jaysan says:

    First printing November 2012 edition :
    Page 107, the first paragraph is also printed at the end of page 103 :
    “The remainder of this chapter… at the end of the chapter.”

  • Danny says:

    In Chapter 2, p. 37, your specification for the double-precision floating-point type is incorrect: “k is an integer ranging from [...] -1075 to 970 for double.”

    The correct range is -1074 to 971.

  • Leave a Reply

    Your Name:
    Your Email Adress:
    Your comment:


    IntelliTect Corporation
    3024 S. Bannen Ct.
    Spokane Valley, WA  99037

    Phone: (509) 315-3400