You are previewing Essential C# 5.0.
O'Reilly logo
Essential C# 5.0

Book Description

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.

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

  • Table of Contents

    1. Title Page
    2. Copyright Page
    3. Microsoft Windows Development Series
    4. Dedication Page
    5. Contents at a Glance
    6. Contents
    7. Figures
    8. Tables
    9. Foreword
    10. Preface
      1. Target Audience for This Book
      2. Features of This Book
      3. How This Book Is Organized
    11. Acknowledgments
    12. About the Authors
    13. 1. Introducing C#
      1. Hello, World
      2. C# Syntax Fundamentals
      3. Console Input and Output
      4. Summary
    14. 2. Data Types
      1. Fundamental Numeric Types
      2. More Fundamental Types
      3. null and void
      4. Categories of Types
      5. Nullable Modifier
      6. Conversions between Data Types
      7. Arrays
      8. Summary
    15. 3. Operators and Control Flow
      1. Operators
      2. Introducing Flow Control
      3. Code Blocks ({})
      4. Code Blocks, Scopes, and Declaration Spaces
      5. Boolean Expressions
      6. Bitwise Operators (<<, >>, |, &, ^, ~)
      7. Control Flow Statements, Continued
      8. Jump Statements
      9. C# Preprocessor Directives
      10. Summary
    16. 4. Methods and Parameters
      1. Calling a Method
      2. Declaring a Method
      3. The using Directive
      4. Returns and Parameters on Main()
      5. Advanced Method Parameters
      6. Recursion
      7. Method Overloading
      8. Optional Parameters
      9. Basic Error Handling with Exceptions
      10. Summary
    17. 5. Classes
      1. Declaring and Instantiating a Class
      2. Instance Fields
      3. Instance Methods
      4. Using the this Keyword
      5. Access Modifiers
      6. Properties
      7. Constructors
      8. Static Members
      9. Extension Methods
      10. Encapsulating the Data
      11. Nested Classes
      12. Partial Classes
      13. Summary
    18. 6. Inheritance
      1. Derivation
      2. Overriding the Base Class
      3. Abstract Classes
      4. All Classes Derive from System.Object
      5. Verifying the Underlying Type with the is Operator
      6. Conversion Using the as Operator
      7. Summary
    19. 7. Interfaces
      1. Introducing Interfaces
      2. Polymorphism through Interfaces
      3. Interface Implementation
      4. Converting between the Implementing Class and Its Interfaces
      5. Interface Inheritance
      6. Multiple Interface Inheritance
      7. Extension Methods on Interfaces
      8. Implementing Multiple Inheritance via Interfaces
      9. Versioning
      10. Interfaces Compared with Classes
      11. Interfaces Compared with Attributes
      12. Summary
    20. 8. Value Types
      1. Structs
      2. Boxing
      3. Enums
      4. Summary
    21. 9. Well-Formed Types
      1. Overriding object Members
      2. Operator Overloading
      3. Referencing Other Assemblies
      4. Defining Namespaces
      5. XML Comments
      6. Garbage Collection
      7. Resource Cleanup
      8. Lazy Initialization
      9. Summary
    22. 10. Exception Handling
      1. Multiple Exception Types
      2. Catching Exceptions
      3. General Catch Block
      4. Guidelines for Exception Handling
      5. Defining Custom Exceptions
      6. Wrapping an Exception and Rethrowing
      7. Summary
    23. 11. Generics
      1. C# without Generics
      2. Introducing Generic Types
      3. Constraints
      4. Generic Methods
      5. Covariance and Contravariance
      6. Generic Internals
      7. Summary
    24. 12. Delegates and Lambda Expressions
      1. Introducing Delegates
      2. Lambda Expressions
      3. Anonymous Methods
      4. General-Purpose Delegates: System.Func and System.Action
      5. Summary
    25. 13. Events
      1. Coding the Observer Pattern with Multicast Delegates
      2. Events
      3. Summary
    26. 14. Collection Interfaces with Standard Query Operators
      1. Anonymous Types and Implicitly Typed Local Variables
      2. Collection Initializers
      3. What Makes a Class a Collection: IEnumerable<T>
      4. Standard Query Operators
      5. Summary
    27. 15. LINQ with Query Expressions
      1. Introducing Query Expressions
      2. Query Expressions Are Just Method Invocations
      3. Summary
    28. 16. Building Custom Collections
      1. More Collection Interfaces
      2. Primary Collection Classes
      3. Providing an Indexer
      4. Returning Null or an Empty Collection
      5. Iterators
      6. Summary
    29. 17. Reflection, Attributes, and Dynamic Programming
      1. Reflection
      2. Attributes
      3. Programming with Dynamic Objects
      4. Summary
    30. 18. Multithreading
      1. Multithreading Basics
      2. Working with System.Threading
      3. Asynchronous Tasks
      4. Canceling a Task
      5. The Task-Based Asynchronous Pattern in C# 5.0
      6. Executing Loop Iterations in Parallel
      7. Running LINQ Queries in Parallel
      8. Summary
    31. 19. Thread Synchronization
      1. Why Synchronization?
      2. Timers
      3. Summary
    32. 20. Platform Interoperability and Unsafe Code
      1. Using the Windows Runtime Libraries from C#
      2. Platform Invoke
      3. Pointers and Addresses
      4. Executing Unsafe Code via a Delegate
      5. Summary
    33. 21. The Common Language Infrastructure
      1. Defining the Common Language Infrastructure (CLI)
      2. CLI Implementations
      3. C# Compilation to Machine Code
      4. Runtime
      5. Application Domains
      6. Assemblies, Manifests, and Modules
      7. Common Intermediate Language (CIL)
      8. Common Type System (CTS)
      9. Common Language Specification (CLS)
      10. Base Class Library (BCL)
      11. Metadata
      12. Summary
    34. A. Downloading and Installing the C# Compiler and CLI Platform
      1. Microsoft’s .NET
    35. B. Tic-Tac-Toe Source Code Listing
    36. C. Interfacing with Mutithreading Patterns Prior to the TPL and C# 5.0
      1. Asynchronous Programming Model
      2. Asynchronous Delegate Invocation
      3. The Event-based Asynchronous Pattern (EAP)
      4. Background Worker Pattern
      5. Dispatching to the Windows UI
    37. D. Timers Prior to the Async/Await Pattern of C# 5.0
    38. Index
    39. Index of 5.0 Topics
    40. Index of 4.0 Topics
    41. Index of 3.0 Topics
    42. IntelliTect
    43. Ad Page