C# 12 in a Nutshell: The Definitive Reference

C# 12 in a Nutshell: The Definitive Reference

C# 12 in a Nutshell: The Definitive Reference
Автор: Albahari Joseph
Дата выхода: 2024
Издательство: O’Reilly Media, Inc.
Количество страниц: 1086
Размер файла: 4.2 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover ....1

Copyright....4

Table of Contents....5

Preface....13

Intended Audience....13

How This Book Is Organized....14

What You Need to Use This Book....14

Conventions Used in This Book....15

Using Code Examples....16

How to Contact Us....16

Acknowledgments....17

Joseph Albahari....17

Chapter 1. Introducing C# and .NET....19

Object Orientation....19

Type Safety....20

Memory Management....21

Platform Support....21

CLRs, BCLs, and Runtimes....21

Common Language Runtime....22

Base Class Library....23

Runtimes....23

Niche Runtimes....26

A Brief History of C#....26

What’s New in C# 12....26

What’s New in C# 11....28

What’s New in C# 10....31

What’s New in C# 9.0....34

What’s New in C# 8.0....37

What’s New in C# 7.x....41

What’s New in C# 6.0....45

What’s New in C# 5.0....46

What’s New in C# 4.0....47

What’s New in C# 3.0....47

What’s New in C# 2.0....48

Chapter 2. C# Language Basics....49

A First C# Program....49

Compilation....51

Syntax....52

Identifiers and Keywords....52

Literals, Punctuators, and Operators....53

Comments....54

Type Basics....54

Predefined Type Examples....54

Custom Types....55

Types and Conversions....60

Value Types Versus Reference Types....61

Predefined Type Taxonomy....64

Numeric Types....65

Numeric Literals....66

Numeric Conversions....67

Arithmetic Operators....68

Increment and Decrement Operators....69

Specialized Operations on Integral Types....69

8- and 16-Bit Integral Types....71

Special Float and Double Values....71

double Versus decimal....72

Real Number Rounding Errors....72

Boolean Type and Operators....73

bool Conversions....73

Equality and Comparison Operators....73

Conditional Operators....74

Strings and Characters....75

Char Conversions....76

String Type....76

UTF-8 Strings....79

Arrays....79

Default Element Initialization....80

Indices and Ranges....81

Multidimensional Arrays....82

Simplified Array Initialization Expressions....83

Bounds Checking....84

Variables and Parameters....85

The Stack and the Heap....85

Definite Assignment....86

Default Values....87

Parameters....87

Ref Locals....93

Ref Returns....94

var—Implicitly Typed Local Variables....95

Target-Typed new Expressions....95

Expressions and Operators....96

Primary Expressions....96

Void Expressions....96

Assignment Expressions....97

Operator Precedence and Associativity....97

Operator Table....98

Null Operators....100

Null-Coalescing Operator....101

Null-Coalescing Assignment Operator....101

Null-Conditional Operator....101

Statements....102

Declaration Statements....102

Expression Statements....103

Selection Statements....104

Iteration Statements....109

Jump Statements....111

Miscellaneous Statements....112

Namespaces....113

File-Scoped Namespaces....114

The using Directive....114

The global using Directive....114

using static....115

Rules Within a Namespace....115

Aliasing Types and Namespaces....117

Advanced Namespace Features....118

Chapter 3. Creating Types in C#....121

Classes....121

Fields....121

Constants....122

Methods....124

Instance Constructors....126

Deconstructors....128

Object Initializers....129

The this Reference....131

Properties....132

Indexers....136

Primary Constructors (C# 12)....137

Static Constructors....140

Static Classes....142

Finalizers....142

Partial Types and Methods....142

The nameof operator....144

Inheritance....144

Polymorphism....145

Casting and Reference Conversions....146

Virtual Function Members....149

Abstract Classes and Abstract Members....150

Hiding Inherited Members....151

Sealing Functions and Classes....152

The base Keyword....152

Constructors and Inheritance....153

Overloading and Resolution....155

The object Type....156

Boxing and Unboxing....157

Static and Runtime Type Checking....158

The GetType Method and typeof Operator....158

The ToString Method....159

Object Member Listing....159

Structs....160

Struct Construction Semantics....160

Read-Only Structs and Functions....161

Ref Structs....162

Access Modifiers....163

Examples....163

Friend Assemblies....164

Accessibility Capping....164

Restrictions on Access Modifiers....165

Interfaces....165

Extending an Interface....166

Explicit Interface Implementation....166

Implementing Interface Members Virtually....167

Reimplementing an Interface in a Subclass....167

Interfaces and Boxing....169

Default Interface Members....169

Static Interface Members....170

Enums....172

Enum Conversions....173

Flags Enums....173

Enum Operators....174

Type-Safety Issues....174

Nested Types....175

Generics....177

Generic Types....177

Why Generics Exist....178

Generic Methods....179

Declaring Type Parameters....180

typeof and Unbound Generic Types....180

The default Generic Value....181

Generic Constraints....181

Subclassing Generic Types....183

Self-Referencing Generic Declarations....183

Static Data....184

Type Parameters and Conversions....184

Covariance....185

Contravariance....188

C# Generics Versus C++ Templates....189

Chapter 4. Advanced C#....191

Delegates....191

Writing Plug-in Methods with Delegates....192

Instance and Static Method Targets....193

Multicast Delegates....194

Generic Delegate Types....195

The Func and Action Delegates....196

Delegates Versus Interfaces....196

Delegate Compatibility....197

Events....199

Standard Event Pattern....201

Event Accessors....205

Event Modifiers....206

Lambda Expressions....206

Explicitly Specifying Lambda Parameter and Return Types....207

Default Lambda Parameters (C# 12)....208

Capturing Outer Variables....208

Lambda Expressions Versus Local Methods....212

Anonymous Methods....212

try Statements and Exceptions....213

The catch Clause....215

The finally Block....216

Throwing Exceptions....218

Key Properties of System.Exception....219

Common Exception Types....220

The TryXXX Method Pattern....221

Alternatives to Exceptions....221

Enumeration and Iterators....221

Enumeration....221

Collection Initializers and Collection Expressions....223

Iterators....224

Iterator Semantics....225

Composing Sequences....226

Nullable Value Types....228

Nullable Struct....228

Implicit and Explicit Nullable Conversions....228

Boxing and Unboxing Nullable Values....229

Operator Lifting....229

bool? with & and | Operators....231

Nullable Value Types and Null Operators....231

Scenarios for Nullable Value Types....232

Alternatives to Nullable Value Types....232

Nullable Reference Types....233

The Null-Forgiving Operator....234

Separating the Annotation and Warning Contexts....235

Treating Nullable Warnings as Errors....235

Extension Methods....235

Extension Method Chaining....236

Ambiguity and Resolution....237

Anonymous Types....238

Tuples....240

Naming Tuple Elements....241

Aliasing Tuples (C# 12)....243

ValueTuple.Create....243

Deconstructing Tuples....243

Equality Comparison....244

The System.Tuple classes....244

Records....245

Background....245

Defining a Record....245

Nondestructive Mutation....249

Property Validation....250

Calculated Fields and Lazy Evaluation....251

Primary Constructors....253

Records and Equality Comparison....255

Patterns....256

Constant Pattern....257

Relational Patterns....257

Pattern Combinators....258

var Pattern....258

Tuple and Positional Patterns....258

Property Patterns....259

List Patterns....261

Attributes....261

Attribute Classes....261

Named and Positional Attribute Parameters....262

Applying Attributes to Assemblies and Backing Fields....262

Applying Attributes to Lambda Expressions....263

Specifying Multiple Attributes....263

Caller Info Attributes....264

CallerArgumentExpression....265

Dynamic Binding....266

Static Binding Versus Dynamic Binding....267

Custom Binding....267

Language Binding....268

RuntimeBinderException....269

Runtime Representation of Dynamic....269

Dynamic Conversions....270

var Versus dynamic....270

Dynamic Expressions....271

Dynamic Calls Without Dynamic Receivers....271

Static Types in Dynamic Expressions....272

Uncallable Functions....273

Operator Overloading....274

Operator Functions....275

Overloading Equality and Comparison Operators....276

Custom Implicit and Explicit Conversions....276

Overloading true and false....277

Static Polymorphism....278

Polymorphic Operators....279

Generic Math....280

Unsafe Code and Pointers....281

Pointer Basics....281

Unsafe Code....282

The fixed Statement....282

The Pointer-to-Member Operator....283

The stackalloc Keyword....283

Fixed-Size Buffers....283

void*....284

Native-Sized Integers....284

Function Pointers....286

[SkipLocalsInit]....287

Preprocessor Directives....288

Conditional Attributes....289

Pragma Warning....290

XML Documentation....290

Standard XML Documentation Tags....291

User-Defined Tags....293

Type or Member Cross-References....293

Chapter 5. .NET Overview....295

Runtime Targets and TFMs....297

.NET Standard....297

.NET Standard 2.0....298

Other .NET Standards....298

.NET Framework and .NET 8 Compatibility....298

Reference Assemblies....299

Runtime and C# Language Versions....299

The CLR and BCL....299

System Types....300

Text Processing....300

Collections....300

Querying....300

XML and JSON....301

Diagnostics....301

Concurrency and Asynchrony....301

Streams and Input/Output....301

Networking....302

Assemblies, Reflection, and Attributes....302

Dynamic Programming....302

Cryptography....302

Advanced Threading....302

Parallel Programming....303

Span and Memory....303

Native and COM Interoperability....303

Regular Expressions....303

Serialization....303

The Roslyn Compiler....303

Application Layers....304

ASP.NET Core....304

Windows Desktop....305

UWP and WinUI 3....306

MAUI....307

Chapter 6. .NET Fundamentals....309

String and Text Handling....309

Char....309

String....311

Comparing Strings....315

StringBuilder....318

Text Encodings and Unicode....319

Dates and Times....322

TimeSpan....322

DateTime and DateTimeOffset....324

DateOnly and TimeOnly....330

Dates and Time Zones....330

DateTime and Time Zones....330

DateTimeOffset and Time Zones....331

TimeZoneInfo....331

Daylight Saving Time and DateTime....334

Formatting and Parsing....335

ToString and Parse....336

Format Providers....336

Standard Format Strings and Parsing Flags....341

Numeric Format Strings....341

NumberStyles....343

Date/Time Format Strings....345

DateTimeStyles....347

Enum Format Strings....348

Other Conversion Mechanisms....348

Convert....348

XmlConvert....350

Type Converters....351

BitConverter....351

Globalization....352

Globalization Checklist....352

Testing....353

Working with Numbers....353

Conversions....353

Math....354

BigInteger....354

Half....355

Complex....356

Random....356

BitOperations....358

Enums....358

Enum Conversions....359

Enumerating Enum Values....361

How Enums Work....361

The Guid Struct....362

Equality Comparison....362

Value Versus Referential Equality....363

Standard Equality Protocols....364

Equality and Custom Types....368

Order Comparison....373

IComparable....374

< and >....375

Implementing the IComparable Interfaces....375

Utility Classes....376

Console....376

Environment....377

Process....378

AppContext....380

Chapter 7. Collections....383

Enumeration....384

IEnumerable and IEnumerator....384

IEnumerable and IEnumerator....385

Implementing the Enumeration Interfaces....387

The ICollection and IList Interfaces....391

ICollection and ICollection....392

IList and IList....393

IReadOnlyCollection and IReadOnlyList....394

The Array Class....395

Construction and Indexing....397

Enumeration....399

Length and Rank....399

Searching....400

Sorting....401

Reversing Elements....402

Copying....402

Converting and Resizing....403

Lists, Queues, Stacks, and Sets....403

List and ArrayList....404

LinkedList....406

Queue and Queue....408

Stack and Stack....409

BitArray....410

HashSet and SortedSet....410

Dictionaries....412

IDictionary....413

IDictionary....414

Dictionary and Hashtable....415

OrderedDictionary....416

ListDictionary and HybridDictionary....417

Sorted Dictionaries....417

Customizable Collections and Proxies....419

Collection and CollectionBase....419

KeyedCollection and DictionaryBase....421

ReadOnlyCollection....424

Immutable Collections....424

Creating Immutable Collections....426

Manipulating Immutable Collections....426

Builders....426

Immutable Collections and Performance....427

Frozen Collections....428

Plugging in Equality and Order....429

IEqualityComparer and EqualityComparer....430

IComparer and Comparer....432

StringComparer....434

IStructuralEquatable and IStructuralComparable....435

Chapter 8. LINQ Queries....437

Getting Started....437

Fluent Syntax....439

Chaining Query Operators....439

Composing Lambda Expressions....442

Natural Ordering....444

Other Operators....445

Query Expressions....445

Range Variables....448

Query Syntax Versus SQL Syntax....448

Query Syntax Versus Fluent Syntax....449

Mixed-Syntax Queries....449

Deferred Execution....450

Reevaluation....451

Captured Variables....452

How Deferred Execution Works....453

Chaining Decorators....454

How Queries Are Executed....455

Subqueries....456

Subqueries and Deferred Execution....459

Composition Strategies....460

Progressive Query Building....460

The into Keyword....461

Wrapping Queries....462

Projection Strategies....463

Object Initializers....463

Anonymous Types....464

The let Keyword....465

Interpreted Queries....466

How Interpreted Queries Work....468

Combining Interpreted and Local Queries....470

AsEnumerable....471

EF Core....472

EF Core Entity Classes....472

DbContext....473

Object Tracking....477

Change Tracking....479

Navigation Properties....480

Deferred Execution....482

Building Query Expressions....484

Delegates Versus Expression Trees....484

Expression Trees....486

Chapter 9. LINQ Operators....489

Overview....490

Sequence→Sequence....491

Sequence→Element or Value....492

Void→Sequence....493

Filtering....493

Where....494

Take, TakeLast, Skip, SkipLast....496

TakeWhile and SkipWhile....497

Distinct and DistinctBy....497

Projecting....498

Select....498

SelectMany....503

Joining....510

Join and GroupJoin....510

The Zip Operator....518

Ordering....518

OrderBy, OrderByDescending, ThenBy, ThenByDescending....519

Grouping....521

GroupBy....521

Chunk....525

Set Operators....525

Concat, Union, UnionBy....525

Intersect, Intersect By, Except, and ExceptBy....526

Conversion Methods....527

OfType and Cast....527

ToArray, ToList, ToDictionary, ToHashSet, ToLookup....529

AsEnumerable and AsQueryable....529

Element Operators....530

First, Last, and Single....530

ElementAt....531

MinBy and MaxBy....531

DefaultIfEmpty....532

Aggregation Methods....532

Count and LongCount....532

Min and Max....533

Sum and Average....533

Aggregate....534

Quantifiers....537

Contains and Any....537

All and SequenceEqual....537

Generation Methods....538

Empty....538

Range and Repeat....538

Chapter 10. LINQ to XML....539

Architectural Overview....539

What Is a DOM?....539

The LINQ to XML DOM....540

X-DOM Overview....540

Loading and Parsing....542

Saving and Serializing....543

Instantiating an X-DOM....544

Functional Construction....544

Specifying Content....545

Automatic Deep Cloning....546

Navigating and Querying....546

Child Node Navigation....547

Parent Navigation....550

Peer Node Navigation....551

Attribute Navigation....551

Updating an X-DOM....552

Simple Value Updates....552

Updating Child Nodes and Attributes....552

Updating Through the Parent....553

Working with Values....555

Setting Values....555

Getting Values....555

Values and Mixed Content Nodes....556

Automatic XText Concatenation....557

Documents and Declarations....557

XDocument....557

XML Declarations....559

Names and Namespaces....561

Namespaces in XML....561

Specifying Namespaces in the X-DOM....563

The X-DOM and Default Namespaces....564

Prefixes....565

Annotations....566

Projecting into an X-DOM....567

Eliminating Empty Elements....569

Streaming a Projection....570

Chapter 11. Other XML and JSON Technologies....571

XmlReader....571

Reading Nodes....572

Reading Elements....573

Reading Attributes....577

Namespaces and Prefixes....578

XmlWriter....579

Writing Attributes....580

Writing Other Node Types....580

Namespaces and Prefixes....581

Patterns for Using XmlReader/XmlWriter....581

Working with Hierarchical Data....581

Mixing XmlReader/XmlWriter with an X-DOM....584

Working with JSON....586

Utf8JsonReader....586

Utf8JsonWriter....589

JsonDocument....590

JsonNode....593

Chapter 12. Disposal and Garbage Collection....599

IDisposable, Dispose, and Close....599

Standard Disposal Semantics....600

When to Dispose....601

Clearing Fields in Disposal....602

Anonymous Disposal....603

Automatic Garbage Collection....605

Roots....606

Finalizers....607

Calling Dispose from a Finalizer....608

Resurrection....610

How the GC Works....611

Optimization Techniques....612

Forcing Garbage Collection....616

Tuning Garbage Collection at Runtime....616

Memory Pressure....617

Array Pooling....617

Managed Memory Leaks....618

Timers....619

Diagnosing Memory Leaks....620

Weak References....621

Weak References and Caching....622

Weak References and Events....622

Chapter 13. Diagnostics....625

Conditional Compilation....625

Conditional Compilation Versus Static Variable Flags....626

The Conditional Attribute....627

Debug and Trace Classes....629

Fail and Assert....629

TraceListener....630

Flushing and Closing Listeners....631

Debugger Integration....632

Attaching and Breaking....632

Debugger Attributes....632

Processes and Process Threads....633

Examining Running Processes....633

Examining Threads in a Process....633

StackTrace and StackFrame....634

Windows Event Logs....636

Writing to the Event Log....636

Reading the Event Log....637

Monitoring the Event Log....637

Performance Counters....638

Enumerating the Available Counters....639

Reading Performance Counter Data....640

Creating Counters and Writing Performance Data....641

The Stopwatch Class....642

Cross-Platform Diagnostic Tools....643

dotnet-counters....643

dotnet-trace....645

dotnet-dump....646

Chapter 14. Concurrency and Asynchrony....649

Introduction....649

Threading....650

Creating a Thread....650

Join and Sleep....652

Blocking....652

Local Versus Shared State....654

Locking and Thread Safety....656

Passing Data to a Thread....657

Exception Handling....658

Foreground Versus Background Threads....660

Thread Priority....660

Signaling....661

Threading in Rich Client Applications....661

Synchronization Contexts....663

The Thread Pool....664

Tasks....666

Starting a Task....666

Returning Values....668

Exceptions....668

Continuations....670

TaskCompletionSource....671

Task.Delay....674

Principles of Asynchrony....674

Synchronous Versus Asynchronous Operations....674

What Is Asynchronous Programming?....675

Asynchronous Programming and Continuations....676

Why Language Support Is Important....677

Asynchronous Functions in C#....679

Awaiting....679

Writing Asynchronous Functions....685

Asynchronous Lambda Expressions....690

Asynchronous Streams....690

Asynchronous Methods in WinRT....693

Asynchrony and Synchronization Contexts....693

Optimizations....695

Asynchronous Patterns....699

Cancellation....699

Progress Reporting....701

The Task-Based Asynchronous Pattern....703

Task Combinators....703

Asynchronous Locking....707

Obsolete Patterns....707

Asynchronous Programming Model....707

Event-Based Asynchronous Pattern....708

BackgroundWorker....709

Chapter 15. Streams and I/O....711

Stream Architecture....711

Using Streams....713

Reading and Writing....715

Seeking....716

Closing and Flushing....717

Timeouts....717

Thread Safety....717

Backing Store Streams....718

FileStream....718

MemoryStream....722

PipeStream....722

BufferedStream....726

Stream Adapters....727

Text Adapters....728

Binary Adapters....733

Closing and Disposing Stream Adapters....734

Compression Streams....736

Compressing in Memory....737

Unix gzip File Compression....738

Working with ZIP Files....739

Working with Tar Files....740

File and Directory Operations....741

The File Class....741

The Directory Class....745

FileInfo and DirectoryInfo....746

Path....747

Special Folders....748

Querying Volume Information....749

Catching Filesystem Events....750

OS Security....751

Running in a Standard User Account....752

Administrative Elevation and Virtualization....753

Memory-Mapped Files....754

Memory-Mapped Files and Random File I/O....754

Memory-Mapped Files and Shared Memory (Windows)....755

Cross-Platform Interprocess Shared Memory....755

Working with View Accessors....756

Chapter 16. Networking....759

Network Architecture....759

Addresses and Ports....761

URIs....762

HttpClient....764

GetAsync and Response Messages....765

SendAsync and Request Messages....766

Uploading Data and HttpContent....766

HttpMessageHandler....767

Proxies....769

Authentication....769

Headers....771

Query Strings....771

Uploading Form Data....772

Cookies....772

Writing an HTTP Server....773

Using DNS....776

Sending Mail with SmtpClient....776

Using TCP....777

Concurrency with TCP....780

Receiving POP3 Mail with TCP....781

Chapter 17. Assemblies....783

What’s in an Assembly....783

The Assembly Manifest....784

The Application Manifest (Windows)....785

Modules....786

The Assembly Class....786

Strong Names and Assembly Signing....788

How to Strongly Name an Assembly....788

Assembly Names....789

Fully Qualified Names....789

The AssemblyName Class....790

Assembly Informational and File Versions....791

Authenticode Signing....791

How to Sign with Authenticode....792

Resources and Satellite Assemblies....794

Directly Embedding Resources....795

.resources Files....796

.resx Files....797

Satellite Assemblies....799

Cultures and Subcultures....800

Loading, Resolving, and Isolating Assemblies....801

Assembly Load Contexts....803

The Default ALC....808

The “Current” ALC....810

Assembly.Load and Contextual ALCs....810

Loading and Resolving Unmanaged Libraries....813

AssemblyDependencyResolver....814

Unloading ALCs....815

The Legacy Loading Methods....816

Writing a Plug-In System....817

Chapter 18. Reflection and Metadata....823

Reflecting and Activating Types....824

Obtaining a Type....824

Type Names....826

Base Types and Interfaces....827

Instantiating Types....828

Generic Types....830

Reflecting and Invoking Members....831

Member Types....833

C# Members Versus CLR Members....834

Generic Type Members....836

Dynamically Invoking a Member....837

Method Parameters....838

Using Delegates for Performance....840

Accessing Nonpublic Members....840

Generic Methods....841

Anonymously Calling Members of a Generic Interface....842

Calling Static Virtual/Abstract Interface Members....844

Reflecting Assemblies....845

Modules....846

Working with Attributes....846

Attribute Basics....847

The AttributeUsage Attribute....848

Defining Your Own Attribute....849

Retrieving Attributes at Runtime....850

Dynamic Code Generation....852

Generating IL with DynamicMethod....852

The Evaluation Stack....853

Passing Arguments to a Dynamic Method....854

Generating Local Variables....855

Branching....856

Instantiating Objects and Calling Instance Methods....856

Exception Handling....858

Emitting Assemblies and Types....859

The Reflection.Emit Object Model....860

Emitting Type Members....862

Emitting Methods....862

Emitting Fields and Properties....864

Emitting Constructors....866

Attaching Attributes....867

Emitting Generic Methods and Types....867

Defining Generic Methods....867

Defining Generic Types....869

Awkward Emission Targets....869

Uncreated Closed Generics....869

Circular Dependencies....871

Parsing IL....873

Writing a Disassembler....873

Chapter 19. Dynamic Programming....879

The Dynamic Language Runtime....879

Dynamic Member Overload Resolution....881

Simplifying the Visitor Pattern....881

Anonymously Calling Members of a Generic Type....884

Implementing Dynamic Objects....887

DynamicObject....887

ExpandoObject....889

Interoperating with Dynamic Languages....890

Passing State Between C# and a Script....891

Chapter 20. Cryptography....893

Overview....893

Windows Data Protection....894

Hashing....895

Hash Algorithms in .NET....896

Hashing Passwords....896

Symmetric Encryption....897

Encrypting in Memory....899

Chaining Encryption Streams....900

Disposing Encryption Objects....901

Key Management....902

Public-Key Encryption and Signing....902

The RSA Class....904

Digital Signing....905

Chapter 21. Advanced Threading....907

Synchronization Overview....908

Exclusive Locking....908

The lock Statement....909

Monitor.Enter and Monitor.Exit....909

Choosing the Synchronization Object....910

When to Lock....911

Locking and Atomicity....912

Nested Locking....913

Deadlocks....914

Performance....915

Mutex....915

Locking and Thread Safety....916

Thread Safety and .NET Types....917

Thread Safety in Application Servers....919

Immutable Objects....921

Nonexclusive Locking....922

Semaphore....922

Reader/Writer Locks....925

Signaling with Event Wait Handles....929

AutoResetEvent....930

ManualResetEvent....933

CountdownEvent....934

Creating a Cross-Process EventWaitHandle....934

Wait Handles and Continuations....935

WaitAny, WaitAll, and SignalAndWait....936

The Barrier Class....937

Lazy Initialization....938

Lazy....939

LazyInitializer....940

Thread-Local Storage....941

[ThreadStatic]....941

ThreadLocal....941

GetData and SetData....942

AsyncLocal....943

Timers....944

PeriodicTimer....945

Multithreaded Timers....946

Single-Threaded Timers....947

Chapter 22. Parallel Programming....949

Why PFX?....950

PFX Concepts....950

PFX Components....951

When to Use PFX....952

PLINQ....953

Parallel Execution Ballistics....955

PLINQ and Ordering....955

PLINQ Limitations....956

Example: Parallel Spellchecker....956

Functional Purity....958

Setting the Degree of Parallelism....959

Cancellation....959

Optimizing PLINQ....960

The Parallel Class....966

Parallel.Invoke....966

Parallel.For and Parallel.ForEach....967

Task Parallelism....972

Creating and Starting Tasks....973

Waiting on Multiple Tasks....974

Canceling Tasks....975

Continuations....976

Task Schedulers....980

TaskFactory....981

Working with AggregateException....982

Flatten and Handle....983

Concurrent Collections....984

IProducerConsumerCollection....985

ConcurrentBag....986

BlockingCollection....987

Writing a Producer/Consumer Queue....988

Chapter 23. Span and Memory....991

Spans and Slicing....992

CopyTo and TryCopyTo....994

Searching in Spans....995

Working with Text....995

Memory....996

Forward-Only Enumerators....998

Working with Stack-Allocated and Unmanaged Memory....1000

Chapter 24. Native and COM Interoperability....1003

Calling into Native DLLs....1003

Type and Parameter Marshaling....1004

Marshaling Common Types....1004

Marshaling Classes and Structs....1006

In and Out Marshaling....1008

Calling Conventions....1008

Callbacks from Unmanaged Code....1009

Callbacks with Function Pointers....1009

Callbacks with Delegates....1011

Simulating a C Union....1012

Shared Memory....1013

Mapping a Struct to Unmanaged Memory....1015

fixed and fixed {...}....1018

COM Interoperability....1019

The Purpose of COM....1020

The Basics of the COM Type System....1020

Calling a COM Component from C#....1021

Optional Parameters and Named Arguments....1022

Implicit ref Parameters....1023

Indexers....1023

Dynamic Binding....1024

Embedding Interop Types....1024

Type Equivalence....1025

Exposing C# Objects to COM....1025

Enabling Registry-Free COM....1027

Chapter 25. Regular Expressions....1029

Regular Expression Basics....1029

Compiled Regular Expressions....1031

RegexOptions....1031

Character Escapes....1032

Character Sets....1033

Quantifiers....1034

Greedy Versus Lazy Quantifiers....1035

Zero-Width Assertions....1035

Lookahead and Lookbehind....1035

Anchors....1037

Word Boundaries....1038

Groups....1038

Named Groups....1039

Replacing and Splitting Text....1040

MatchEvaluator Delegate....1040

Splitting Text....1041

Cookbook Regular Expressions....1041

Recipes....1041

Regular Expressions Language Reference....1045

Index....1049

When you have questions about C# 12 or .NET 8, this best-selling guide has the answers you need. C# is a language of unusual flexibility and breadth, and with its continual growth, there's always so much more to learn. In the tradition of O'Reilly's Nutshell guides, this thoroughly updated edition is simply the best one-volume reference to the C# language available today.

 Aimed at intermediate and advanced programmers, this is a book whose explanations get straight to the point, covering C#, the CLR, and the core .NET libraries in depth without long intros or bloated samples.

  • Get up to speed on C# from syntax and variables to advanced topics such as pointers, closures, and patterns
  • Dig deep into LINQ, with three chapters dedicated to the topic
  • Explore concurrency and asynchrony, advanced threading, and parallel programming
  • Work with .NET features including regular expressions, networking, assemblies, spans, cryptography, and reflection.emit

Похожее:

Список отзывов:

Нет отзывов к книге.