C# 12 Pocket Reference: Instant Help for C# 12 Programmers

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Looking for quick answers for using C# 12? 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.

Author(s): Joseph Albahari
Publisher: O'Reilly Media
Year: 2023

Language: English
Pages: 287

A First C# Program
Identifiers and Keywords
Avoiding conflicts
Contextual keywords
Literals, Punctuators, and Operators
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
The public keyword
Creating a namespace
Defining a Main method
Top-level statements
Types and Conversions
Value Types Versus Reference Types
Value types
Reference types
Predefined Type Taxonomy
Numeric Types
Numeric Literals
Numeric literal type inference
Numeric suffixes
Numeric Conversions
Integral-to-integral conversions
Real-to-real conversions
Real-to-integral conversions
Arithmetic Operators
Increment and Decrement Operators
Specialized Integral Operations
The checked and unchecked operators
Bitwise operators
8- and 16-Bit Integral Types
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
String Type
Raw string literals (C# 11)
String concatenation
String interpolation
String comparisons
Searching within strings
Manipulating strings
UTF-8 Strings
Default Element Initialization
Indices and Ranges
Multidimensional Arrays
Rectangular arrays
Jagged arrays
Simplified Array Initialization Expressions
Variables and Parameters
The Stack and the Heap
Definite Assignment
Default Values
Passing arguments by value
The ref modifier
The out modifier
Out variables and discards
The in modifier
The params modifier
Optional parameters
Named arguments
var—Implicitly Typed Local Variables
Target-Typed new Expressions
Expressions and Operators
Assignment Expressions
Operator Precedence and Associativity
Left-associative operators
Right-associative operators
Operator Table
Null Operators
Null-Coalescing Operator
Null-Coalescing Assignment Operator
Null-Conditional Operator
Declaration Statements
Local variable scope
Expression Statements
Selection Statements
The if statement
The else clause
Changing the flow of execution with braces
The switch statement
Switching on types
Switch expressions
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
File-Scoped Namespaces
The using Directive
The global using Directive
using static
Rules Within a Namespace
Name scoping
Name hiding
Repeated namespaces
The global:: qualifier
Aliasing Types and Namespaces
Alias any type (C# 12)
Expression-bodied methods
Local methods
Static local methods
Overloading methods
Instance Constructors
Implicit parameterless constructors
Nonpublic constructors
Object Initializers
The this Reference
Expression-bodied properties
Automatic properties
Property initializers
get and set accessibility
Init-only setters
Implementing an indexer
Using indices and ranges with indexers
Primary Constructors (C# 12)
Primary constructor semantics
Primary constructors and field/property initializers
Masking primary constructor parameters
Validating primary constructor parameters
Static Constructors
Static Classes
Partial Types and Methods
Partial methods
Extended partial methods
The nameof Operator
Casting and Reference Conversions
The as operator
The is operator
Virtual Function Members
Covariant returns
Abstract Classes and Abstract Members
Hiding Inherited Members
Sealing Functions and Classes
The base Keyword
Constructors and Inheritance
Required members (C# 11)
Constructor and field initialization order
Inheritance with primary constructors
Overloading and Resolution
The object Type
Boxing and Unboxing
Static and Runtime Type Checking
The GetType Method and typeof Operator
Object Member Listing
Equals, ReferenceEquals, and GetHashCode
The ToString Method
Struct Construction Semantics
readonly Structs and Functions
Access Modifiers
Friend Assemblies
Accessibility Capping
Extending an Interface
Explicit Interface Implementation
Implementing Interface Members Virtually
Reimplementing an Interface in a Subclass
Default Interface Members
Static Interface Members
Static nonvirtual interface members
Static virtual/abstract interface members
Enum Conversions
Flags Enums
Enum Operators
Nested Types
Generic Types
Generic Methods
Declaring Type Parameters
typeof and Unbound Generic Types
The default Generic Value
Generic Constraints
Subclassing Generic Types
Self-Referencing Generic Declarations
Static Data
Writing Plug-In Methods with Delegates
Instance and Static Method Targets
Multicast Delegates
Generic Delegate Types
The Func and Action Delegates
Delegate Compatibility
Return type variance
Parameter variance
Type parameter variance for generic delegates
Standard Event Pattern
Event Accessors
Lambda Expressions
Default Lambda Parameters (C# 12)
Capturing Outer Variables
Static lambdas
Capturing iteration variables
Lambda Expressions Versus Local Methods
Anonymous Methods
try Statements and Exceptions
The catch Clause
Exception filters
The finally Block
The using statement
using declarations
Throwing Exceptions
throw expressions
Rethrowing an exception
Key Properties of System.Exception
Enumeration and Iterators
Collection Initializers and Collection Expressions
Iterator Semantics
Multiple yield statements
yield break
Composing Sequences
Nullable Value Types
Nullable Struct
Nullable Conversions
Boxing/Unboxing Nullable Values
Operator Lifting
Equality operators (==, !=)
Relational operators (<, <=, >=, >)
All other operators (+, −, *, /, %, &, |, ^, <<, >>, +, ++, --, !, ~)
Mixing nullable and non-nullable types
bool? with & and | Operators
Nullable Types and Null Operators
Nullable Reference Types
Extension Methods
Extension Method Chaining
Ambiguity and Resolution
Anonymous Types
Naming Tuple Elements
Deconstructing Tuples
Defining a Record
Parameter lists
Nondestructive Mutation
Primary Constructors
Records and Equality Comparison
var Pattern
Constant Pattern
Relational Patterns
Pattern Combinators
Tuple and Positional Patterns
Property Patterns
List Patterns
LINQ Fundamentals
A simple query
Take and Skip
Element operators
Aggregation operators
Set operators
Deferred Execution
Standard Query Operators
Chaining Query Operators
Query Expressions
Query expressions versus fluent queries
The let Keyword
Query Continuations
Multiple Generators
OfType and Cast
Dynamic Binding
Static Binding Versus Dynamic Binding
Custom Binding
Language Binding
Runtime Representation of dynamic
Dynamic Conversions
var Versus dynamic
Dynamic Expressions
Dynamic Member Overload Resolution
Uncallable Functions
Operator Overloading
Operator Functions
Overloading Equality and Comparison Operators
Custom Implicit and Explicit Conversions
Attribute Classes
Named and Positional Attribute 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
Asynchronous Lambda Expressions
Asynchronous Streams
Static Polymorphism
Polymorphic Operators
Generic Math
Unsafe Code and Pointers
Pointer Basics
Unsafe Code
The fixed Statement
The Pointer-to-Member Operator
The stackalloc Keyword
Fixed-Size Buffers
Function Pointers
Preprocessor Directives
Pragma Warning
XML Documentation
Standard XML Documentation Tags