C# 9.0 Pocket Reference

Book description

Looking for quick answers for using C# 9.0? This tightly focused and practical guide tells you exactly what you need to know without long intros or bloated samples. Succinct and easy to browse, this pocket reference is an ideal quick source of information. If you know Java, C++, or an earlier C# version, this guide will help you get rapidly up to speed.

All programs and code snippets are available as interactive samples in LINQPad. You can edit these samples and instantly see the results without needing to set up projects in Visual Studio. Written by the authors of C# 9.0 in a Nutshell, this pocket reference covers:

  • C# fundamentals and features new to C# 9.0
  • Advanced topics like operator overloading, type constraints, nullable types, operator lifting, closures, patterns, and asynchronous functions
  • LINQ: sequences, lazy execution, standard query operators, and query expressions
  • Unsafe code and pointers, custom attributes, preprocessor directives, and XML documentation

Publisher resources

View/Submit Errata

Table of contents

  1. A First C# Program
    1. Compilation
  2. Syntax
    1. Identifiers and Keywords
    2. Literals, Punctuators, and Operators
    3. Comments
  3. Type Basics
    1. Predefined Type Examples
    2. Custom Type Examples
    3. Types and Conversions
    4. Value Types Versus Reference Types
    5. Predefined Type Taxonomy
  4. Numeric Types
    1. Numeric Literals
    2. Numeric Conversions
    3. Arithmetic Operators
    4. Increment and Decrement Operators
    5. Specialized Integral Operations
    6. 8- and 16-Bit Integral Types
    7. Special Float and Double Values
    8. double Versus decimal
    9. Real Number Rounding Errors
  5. Boolean Type and Operators
    1. Equality and Comparison Operators
    2. Conditional Operators
  6. Strings and Characters
    1. String Type
  7. Arrays
    1. Default Element Initialization
    2. Indices and Ranges
    3. Multidimensional Arrays
    4. Simplified Array Initialization Expressions
  8. Variables and Parameters
    1. The Stack and the Heap
    2. Definite Assignment
    3. Default Values
    4. Parameters
    5. var—Implicitly Typed Local Variables
    6. Target-Typed new Expressions (C# 9)
  9. Expressions and Operators
    1. Assignment Expressions
    2. Operator Precedence and Associativity
    3. Operator Table
  10. Null Operators
    1. Null-Coalescing Operator
    2. Null-Coalescing Assignment Operator
    3. Null-Conditional Operator
  11. Statements
    1. Declaration Statements
    2. Expression Statements
    3. Selection Statements
    4. Iteration Statements
    5. Jump Statements
  12. Namespaces
    1. The using Directive
    2. using static
    3. Rules Within a Namespace
    4. Aliasing Types and Namespaces
  13. Classes
    1. Fields
    2. Constants
    3. Methods
    4. Instance Constructors
    5. Deconstructors
    6. Object Initializers
    7. The this Reference
    8. Properties
    9. Indexers
    10. Static Constructors
    11. Static Classes
    12. Finalizers
    13. Partial Types and Methods
    14. The nameof Operator
  14. Inheritance
    1. Polymorphism
    2. Casting and Reference Conversions
    3. Virtual Function Members
    4. Abstract Classes and Abstract Members
    5. Hiding Inherited Members
    6. Sealing Functions and Classes
    7. The base Keyword
    8. Constructors and Inheritance
    9. Overloading and Resolution
  15. The object Type
    1. Boxing and Unboxing
    2. Static and Runtime Type Checking
    3. The GetType Method and typeof Operator
    4. Object Member Listing
    5. Equals, ReferenceEquals, and GetHashCode
    6. The ToString Method
  16. Structs
    1. Struct Construction Semantics
    2. readonly Structs and Functions
  17. Access Modifiers
    1. Friend Assemblies
    2. Accessibility Capping
  18. Interfaces
    1. Extending an Interface
    2. Explicit Interface Implementation
    3. Implementing Interface Members Virtually
    4. Reimplementing an Interface in a Subclass
    5. Default Interface Members
  19. Enums
    1. Enum Conversions
    2. Flags Enums
    3. Enum Operators
  20. Nested Types
  21. Generics
    1. Generic Types
    2. Generic Methods
    3. Declaring Type Parameters
    4. typeof and Unbound Generic Types
    5. The default Generic Value
    6. Generic Constraints
    7. Subclassing Generic Types
    8. Self-Referencing Generic Declarations
    9. Static Data
    10. Covariance
    11. Contravariance
  22. Delegates
    1. Writing Plug-In Methods with Delegates
    2. Instance and Static Method Targets
    3. Multicast Delegates
    4. Generic Delegate Types
    5. The Func and Action Delegates
    6. Delegate Compatibility
  23. Events
    1. Standard Event Pattern
    2. Event Accessors
  24. Lambda Expressions
    1. Capturing Outer Variables
    2. Lambda Expressions Versus Local Methods
  25. Anonymous Methods
  26. try Statements and Exceptions
    1. The catch Clause
    2. The finally Block
    3. Throwing Exceptions
    4. Key Properties of System.Exception
  27. Enumeration and Iterators
    1. Enumeration
    2. Collection Initializers
    3. Iterators
    4. Iterator Semantics
    5. Composing Sequences
  28. Nullable Value Types
    1. Nullable<T> Struct
    2. Nullable Conversions
    3. Boxing/Unboxing Nullable Values
    4. Operator Lifting
    5. bool? with & and | Operators
    6. Nullable Types and Null Operators
  29. Nullable Reference Types
  30. Extension Methods
    1. Extension Method Chaining
    2. Ambiguity and Resolution
  31. Anonymous Types
  32. Tuples
    1. Naming Tuple Elements
    2. Deconstructing Tuples
  33. Records (C# 9)
    1. Defining a Record
    2. Nondestructive Mutation
    3. Primary Constructors
    4. Records and Equality Comparison
  34. Patterns
    1. var Pattern
    2. Constant Pattern
    3. Relational Patterns (C# 9)
    4. Pattern Combinators (C# 9)
    5. Tuple and Positional Patterns
    6. Property Patterns
  35. LINQ
    1. LINQ Fundamentals
    2. Deferred Execution
    3. Standard Query Operators
    4. Chaining Query Operators
    5. Query Expressions
    6. The let Keyword
    7. Query Continuations
    8. Multiple Generators
    9. Joining
    10. Ordering
    11. Grouping
    12. OfType and Cast
  36. Dynamic Binding
    1. Static Binding Versus Dynamic Binding
    2. Custom Binding
    3. Language Binding
    4. RuntimeBinderException
    5. Runtime Representation of dynamic
    6. Dynamic Conversions
    7. var Versus dynamic
    8. Dynamic Expressions
    9. Dynamic Member Overload Resolution
    10. Uncallable Functions
  37. Operator Overloading
    1. Operator Functions
    2. Overloading Equality and Comparison Operators
    3. Custom Implicit and Explicit Conversions
  38. Attributes
    1. Attribute Classes
    2. Named and Positional Attribute Parameters
    3. Attribute Targets
    4. Specifying Multiple Attributes
    5. Writing Custom Attributes
    6. Retrieving Attributes at Runtime
  39. Caller Info Attributes
  40. Asynchronous Functions
    1. The await and async Keywords
    2. Capturing Local State
    3. Writing Asynchronous Functions
    4. Parallelism
    5. Asynchronous Lambda Expressions
    6. Asynchronous Streams
  41. Unsafe Code and Pointers
    1. Pointer Basics
    2. Unsafe Code
    3. The fixed Statement
    4. The Pointer-to-Member Operator
    5. The stackalloc Keyword
    6. Fixed-Size Buffers
    7. void*
    8. Function Pointers (C# 9)
  42. Preprocessor Directives
    1. Pragma Warning
  43. XML Documentation
    1. Standard XML Documentation Tags
  44. Index

Product information

  • Title: C# 9.0 Pocket Reference
  • Author(s): Joseph Albahari, Ben Albahari
  • Release date: January 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098101138