A First C# Program
Compilation
Syntax
Identifiers and Keywords
Avoiding conflicts
Contextual keywords
Literals, Punctuators, and Operators
Comments
Type Basics
Predefined Type Examples
Custom Type Examples
Members of a type
Symmetry of predefined types and custom types
Constructors and instantiation
Instance versus static members
Conversions
Value Types versus Reference Types
Value types
Reference types
Null
Storage overhead
Predefined Type Taxonomy
Numeric Types
Numeric Literals
Numeric literal type inference
Numeric suffixes
Numeric Conversions
Integral to integral conversions
Floating-point to floating-point conversions
Floating-point to integral conversions
Decimal conversions
Arithmetic Operators
Increment and Decrement Operators
Specialized Integral Operations
Integral division
Integral overflow
Integral arithmetic overflow check operators
Overflow checking for constant expressions
Bitwise operators
8- and 16-Bit Integrals
Special Float and Double Values
double versus decimal
Real Number Rounding Errors
Boolean Type and Operators
Equality and Comparison Operators
Conditional Operators
Strings and Characters
Char Type
Char conversions
String Type
String concatenation
String interpolation
String comparisons
Searching within strings
Manipulating strings
Arrays
Default Element Initialization
Value types versus reference types
Multidimensional Arrays
Rectangular arrays
Jagged arrays
Simplified Array Initialization Expressions
Bounds Checking
Variables and Parameters
The Stack and the Heap
Stack
Heap
Definite Assignment
Default Values
Parameters
Passing arguments by value
The ref modifier
The out modifier
Implications of passing by reference
Out variables and discards
The params modifier
Optional parameters
Named arguments
var—Implicitly Typed Local Variables
Expressions and Operators
Primary Expressions
Void Expressions
Assignment Expressions
Operator Precedence and Associativity
Precedence
Left-associative operators
Right-associative operators
Operator Table
Null Operators
Null Coalescing Operator
Null-conditional Operator
Statements
Declaration Statements
Local variables
Expression Statements
Selection Statements
The if statement
The else clause
Changing the flow of execution with braces
The switch statement
The switch statement with patterns
Iteration Statements
while and do-while loops
for loops
foreach loops
Jump Statements
The break statement
The continue statement
The goto statement
The return statement
The throw statement
Miscellaneous Statements
Namespaces
The using Directive
using static
Rules within a Namespace
Name scoping
Name hiding
The global:: qualifier
Repeated namespaces
Aliasing Types and Namespaces
Classes
Fields
Field initialization
Declaring multiple fields together
Methods
Expression-bodied methods
Overloading methods
Local methods
Pass-by-value versus pass-by-reference
Instance Constructors
Overloading constructors
Implicit parameterless constructors
Constructor and field initialization order
Nonpublic constructors
Deconstructors
Object Initializers
The this Reference
Properties
Read-only and calculated properties
Expression-bodied properties
Automatic properties
Property initializers
get and set accessibility
Indexers
Implementing an indexer
Constants
Static Constructors
Nondeterminism of static constructors
Static Classes
Finalizers
Partial Classes and Methods
Partial methods
The nameof operator
Inheritance
Polymorphism
Casting
Upcasting
Downcasting
The as operator
The is operator
Virtual Function Members
Abstract Classes and Abstract Members
Hiding Inherited Members
Sealing Functions and Classes
The base Keyword
Constructors and Inheritance
Implicit calling of the base class constructor
Constructor and field initialization order
Overloading and Resolution
The object Type
Boxing and Unboxing
Copying semantics of boxing and unboxing
Static and Dynamic Type Checking
Object Member Listing
GetType() and typeof
Equals, ReferenceEquals & GetHashCode
The ToString Method
Structs
Struct Construction Semantics
Access Modifiers
Friend Assemblies
Accessibility Capping
Restrictions on Access Modifiers
Interfaces
Extending an Interface
Explicit Interface Implementation
Implementing Interface Members Virtually
Reimplementing an Interface in a Subclass
Enums
Enum Conversions
Flags Enumerations
Enum Operators
Nested Types
Generics
Generic Types
Why Generics Exist
Generic Methods
Declaring Generic Parameters
typeof and Generics
The default Generic Value
Generic Constraints
Generics and Covariance
Subclassing Generic Types
Self-Referencing Generic Declarations
Covariance
Contravariance
Static Data
Delegates
Writing Plug-in Methods with Delegates
Multicast Delegates
Instance vs. Static Method Targets
Generic Delegate Types
Delegate Compatibility
Type compatibility
Return type variance
Parameter variance
Type parameter variance for generic delegates
Events
Standard Event Pattern
Event Accessors
Event Modifiers
Lambda Expressions
Explicitly Specifying Lambda Parameter Types
Generic Lambda Expressions and the Func Delegates
Outer Variables
Anonymous Methods
try Statements and Exceptions
The catch Clause
Exception filters
The finally Block
The using statement
Throwing Exceptions
throw expressions
Rethrowing an exception
Key Properties of System.Exception
Common Exception Types
Enumeration and Iterators
Enumeration
Iterators
Iterator Semantics
Multiple yield statements
yield break
Composing Sequences
Nullable Types
Null Basics
Nullable<T> struct
Implicit and explicit nullable conversions
Boxing and unboxing nullable values
Lifted Operators
Equality operators (== !=)
Relational operators (< <= >= >)
All other operators (+ - * / % & | ^ << >> + ++ - -- ! ~)
Mixing nullable and nonnullable operators
bool?
Null Coalescing Operator
Operator Overloading
Operator Functions
Overloading Equality and Comparison Operators
Custom Implicit and Explicit Conversions
Extension Methods
Extension Method Chaining
Ambiguity and Resolution
Namespaces
Extension methods versus instance methods
Extension methods versus extension methods
Anonymous Types
Tuples
LINQ
LINQ Fundamentals
A simple query
Projecting
Take and Skip
Element operators
Aggregation operators
Quantifiers
Set operators
Deferred Execution
Standard Query Operators
Chaining Query Operators
Query Syntax
Query syntax versus lambda syntax
The let Keyword
Query Continuations
Multiple Generators
Joining
GroupJoin
Zip
Ordering
Grouping
OfType and Cast
Dynamic Binding
Static Binding vs Dynamic Binding
Custom Binding
Language Binding
RuntimeBinderException
Runtime Representation of dynamic
Dynamic Conversions
var vs dynamic
Dynamic Expressions
Dynamic Member Overload Resolution
Uncallable Functions
Attributes
Attribute Classes
Named and Positional Parameters
Attribute Targets
Specifying Multiple Attributes
Writing Custom Attributes
Retrieving Attributes at Runtime
Caller Info Attributes
Asynchronous Functions
The await and async keywords
Capturing Local State
Writing Asynchronous Functions
Returning Task<TResult>
Parallelism
Asynchronous Lambda Expressions
Unsafe Code and Pointers
Pointer Basics
Unsafe Code
The fixed Statement
The Pointer-to-Member Operator
Arrays
The stackalloc keyword
Fixed-size buffers
void*
Pointers to Unmanaged Code
Preprocessor Directives
Conditional Attributes
Pragma Warning
XML Documentation
Standard XML Documentation Tags