Contents
Figures
Tables
Foreword
Preface
Acknowledgments
About the Authors
1 Introducing C#
Hello, World
C# Syntax Fundamentals
Console Input and Output
2 Data Types
Fundamental Numeric Types
More Fundamental Types
null and void
Categories of Types
Nullable Modifier
Conversions between Data Types
Arrays
3 Operators and Control Flow
Operators
Introducing Flow Control
Code Blocks ({})
Code Blocks, Scopes, and Declaration Spaces
Boolean Expressions
Bitwise Operators (<<, >>, |, &, ^, ~)
Control Flow Statements, Continued
Jump Statements
C# Preprocessor Directives
4 Methods and Parameters
Calling a Method
Declaring a Method
The using Directive
Returns and Parameters on Main()
Advanced Method Parameters
Recursion
Method Overloading
Optional Parameters
Basic Error Handling with Exceptions
5 Classes
Declaring and Instantiating a Class
Instance Fields
Instance Methods
Using the this Keyword
Access Modifiers
Properties
Constructors
Static Members
Extension Methods
Encapsulating the Data
Nested Classes
Partial Classes
6 Inheritance
Derivation
Overriding the Base Class
Abstract Classes
All Classes Derive from System.Object
Verifying the Underlying Type with the is Operator
Conversion Using the as Operator
7 Interfaces
Introducing Interfaces
Polymorphism through Interfaces
Interface Implementation
Converting between the Implementing Class and Its Interfaces
Interface Inheritance
Multiple Interface Inheritance
Extension Methods on Interfaces
Implementing Multiple Inheritance via Interfaces
Versioning
Interfaces Compared with Classes
Interfaces Compared with Attributes
8 Value Types
Structs
Boxing
Enums
9 Well-Formed Types
Overriding object Members
Operator Overloading
Referencing Other Assemblies
Defining Namespaces
XML Comments
Garbage Collection
Resource Cleanup
Lazy Initialization
10 Exception Handling
Multiple Exception Types
Catching Exceptions
General Catch Block
Guidelines for Exception Handling
Defining Custom Exceptions
Rethrowing a Wrapped Exception
11 Generics
C# without Generics
Introducing Generic Types
Constraints
Generic Methods
Covariance and Contravariance
Generic Internals
12 Delegates and Lambda Expressions
Introducing Delegates
Lambda Expressions
Anonymous Methods
General-Purpose Delegates: System.Func and System.Action
13 Events
Coding the Observer Pattern with Multicast Delegates
Events
14 Collection Interfaces with Standard Query Operators
Anonymous Types and Implicitly Typed Local Variables
Collection Initializers
What Makes a Class a Collection: IEnumerable
Standard Query Operators
15 LINQ with Query Expressions
Introducing Query Expressions
Query Expressions Are Just Method Invocations
16 Building Custom Collections
More Collection Interfaces
Primary Collection Classes
Providing an Indexer
Returning Null or an Empty Collection
Iterators
17 Reflection, Attributes, and Dynamic Programming
Reflection
nameof Operator
Attributes
Programming with Dynamic Objects
18 Multithreading
Multithreading Basics
Working with System.Threading
Asynchronous Tasks
Canceling a Task
The Task-Based Asynchronous Pattern
Executing Loop Iterations in Parallel
Running LINQ Queries in Parallel
19 Thread Synchronization
Why Synchronization?
Timers
20 Platform Interoperability and Unsafe Code
Platform Invoke
Pointers and Addresses
Executing Unsafe Code via a Delegate
Using the Windows Runtime Libraries from C#
21 The Common Language Infrastructure
Defining the Common Language Infrastructure
CLI Implementations
C# Compilation to Machine Code
Runtime
Application Domains
Assemblies, Manifests, and Modules
Common Intermediate Language
Common Type System
Common Language Specification
Base Class Library
Metadata
A: Downloading and Installing the C# Compiler and CLI Platform
Microsoft’s .NET
B: Tic-Tac-Toe Source Code Listing
C: Interfacing with Multithreading Patterns prior to the TPL and C# 6.0
D: Timers Prior to the Async/Await Pattern of C# 5.0
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Index of 6.0 Topics
A
B
C
D
E
I
M
N
O
P
R
S
T
U
V
W
Index of 5.0 Topics
A
B
C
D
E
G
H
I
L
M
N
O
P
R
S
T
U
W
Index of 4.0 Topics
A
B
C
D
E
F
G
H
I
L
M
N
O
P
R
S
T
U
W
Index of 3.0 Topics
A
B
C
D
E
F
G
I
J
L
M
N
O
P
Q
R
S
T
U
V
W