Cover....1
Title Page....7
Copyright Page....8
About the Author....11
Acknowledgments....13
Contents....15
Introduction....41
The World of .NET....41
The World of C#....42
What’s New in C#....42
What’s New in ASP.NET Core....43
What’s New with Windows....43
What You Need to Write and Run C# Code....43
What This Book Covers....44
Part I, “The C# Language”....44
Part II, “Libraries”....45
Part III, “Web Applications and Services”....46
Part IV, “Apps”....46
Conventions....47
Source Code....47
Errata....48
Part I The C# Language....49
Chapter 1 .NET Applications and Tools....51
From .NET Framework to .NET Core to .NET....51
.NET Terms....52
.NET SDK....52
.NET Runtime....53
Common Language Runtime....54
.NET Compiler Platform....54
.NET Framework....54
.NET Core....54
.NET....55
.NET Standard....55
NuGet Packages....56
Namespaces....57
.NET Support Length....57
Application Types and Technologies....58
Data Access....58
Windows Apps....59
Web Applications....59
Services....60
SignalR....60
Microsoft Azure....60
Software as a Service....61
Infrastructure as a Service....61
Platform as a Service....61
Functions as a Service....61
Developer Tools....62
.NET CLI....62
Visual Studio Code....62
Visual Studio Community....62
Visual Studio Professional....63
Visual Studio Enterprise....63
Visual Studio for Mac....63
Windows Terminal....63
WSL 2....63
Docker Desktop....64
Using the .NET CLI....64
Creating the Application....64
Top-Level Statements....65
Selecting the Framework and Language Versions....66
Building the Application....66
Running the Application....67
Creating a Web Application....68
Publishing the Application....69
Self-Contained Deployments....69
Creating a Single Executable....70
ReadyToRun....70
Trimming....70
Summary....71
Chapter 2 Core C#....72
Fundamentals of C#....73
Top-Level Statements....73
Variables....74
Command-Line Arguments....75
Understanding Variable Scope....75
Constants....76
Methods and Types with Top-Level Statements....77
Nullable Types....78
Nullable Value Types....78
Nullable Reference Types....79
Using Predefined Types....81
Integer Types....81
Big Integer....81
Native Integer Types....81
Digit Separators....82
Binary Values....82
Floating-Point Types....82
The Boolean Type....83
The Character Type....83
Literals for Numbers....84
The object Type....84
Controlling Program Flow....85
The if Statement....85
Pattern Matching with the is Operator....85
The switch Statement....86
Pattern Matching with the switch Statement....87
The switch Expression....88
The for Loop....90
The while Loop....91
The do-while Loop....91
The foreach Loop....91
Exiting Loops....92
Organization with Namespaces....92
The using Directive....93
Namespace Aliases....93
Working with Strings....93
Using the StringBuilder....94
String Interpolation....94
FormattableString....95
String Formats....95
Verbatim Strings....96
Ranges with Strings....96
Comments....97
Internal Comments Within the Source Files....97
XML Documentation....97
C# Preprocessor Directives....99
#define and #undef....99
#if, #elif, #else, and #endif....100
#warning and #error....100
#region and #endregion....101
#line....101
#pragma....101
#nullable....102
C# Programming Guidelines....102
Rules for Identifiers....102
Usage Conventions....102
Naming Conventions....103
Casing of Names....103
Name Styles....104
Namespace Names....104
Names and Keywords....105
Use of Properties and Methods....105
Use of Fields....106
Summary....106
Chapter 3 Classes, Records, Structs, and Tuples....107
Creating and Using Types....108
Pass by Value or by Reference....108
Classes....110
Fields....111
Readonly Fields....112
Properties....113
Auto-ImplementedProperties....113
Access Modifiers for Properties....114
Readonly Properties....114
Expression-BodiedProperties....114
Auto-ImplementedRead-OnlyProperties....115
Init-OnlySet Accessors....115
Methods....116
Declaring Methods....116
Expression-BodiedMethods....116
Invoking Methods....116
Method Overloading....117
Named Arguments....118
Optional Arguments....118
Variable Number of Arguments....119
Constructors....120
Expression Bodies with Constructors....121
Calling Constructors from Other Constructors....121
Static Constructors....122
Local Functions....122
Generic Methods....123
Extension Methods....123
Anonymous Types....124
Records....125
Immutable Types....125
Nominal Records....125
Positional Records....126
Equality Comparison with Records....126
With Expressions....127
Structs....127
Enum Types....128
ref, in, and out....131
ref Parameters....131
in Parameters....132
ref return....132
out Parameters....133
Tuples....134
Declaring and Initializing Tuples....134
Tuple Deconstruction....135
Returning Tuples....136
ValueTuple....136
Deconstruction....136
Pattern Matching....137
Pattern Matching with Tuples....137
Property Pattern....139
Partial Types....140
Summary....142
Chapter 4 Object-Oriented Programming in C#....143
Object Orientation....144
Inheritance with Classes....144
Virtual Methods....145
Hiding Methods....147
Calling Base Versions of Methods....148
Abstract Classes and Methods....149
Sealed Classes and Methods....150
Constructors of Derived Classes....150
Modifiers....152
Access Modifiers....152
Other Modifiers....153
Inheritance with Records....154
Using Interfaces....155
Predefined Interfaces....155
Dependency Injection with Interfaces....157
Explicit and Implicit Implemented Interfaces....159
Comparing Interfaces and Classes....160
Default Interface Methods....160
Avoiding Breaking Changes....160
Traits with C#....161
Generics....163
Constraints....165
Summary....166
Chapter 5 Operators and Casts....167
Operators....168
Compound Assignment Operators....169
The Conditional-Expression Operator (?:)....169
The checked and unchecked Operators....170
The is and as Operators....171
The sizeof Operator....172
The typeof Operator....172
The nameof Expression....172
The Indexer....173
The Null-Coalescing and Null-Coalescing Assignment Operators....173
The Null-Conditional Operator....174
Using Binary Operators....175
Shifting Bits....177
Signed and Unsigned Numbers....178
Type Safety....180
Type Conversions....180
Implicit Conversions....180
Explicit Conversions....181
Boxing and Unboxing....183
Operator Overloading....184
How Operators Work....184
Operator Overloading with the Vector Type....185
Comparing Objects for Equality....187
Implementing Custom Indexers....190
User-Defined Conversions....191
Implementing User-Defined Casts....192
Casts Between Classes....195
Casts Between Base and Derived Classes....196
Boxing and Unboxing Casts....197
Multiple Casting....198
Summary....200
Chapter 6 Arrays....201
Multiple Objects of the Same Type....202
Simple Arrays....202
Array Declaration and Initialization....202
Accessing Array Elements....203
Using Reference Types....204
Multidimensional Arrays....205
Jagged Arrays....206
Array Class....207
Creating Arrays....207
Copying Arrays....208
Sorting....208
Arrays as Parameters....211
Enumerators....211
IEnumerator Interface....212
foreach Statement....212
yield Statement....212
Using Span with Arrays....215
Creating Slices....215
Changing Values Using Spans....216
ReadOnly Spans....217
Indices and Ranges....218
Indices and the Hat Operator....218
Ranges....218
Efficiently Changing Array Content....219
Indices and Ranges with Custom Collections....220
Array Pools....220
Creating the Array Pool....221
Renting Memory from the Pool....221
Returning Memory to the Pool....222
BitArray....222
Summary....224
Chapter 7 Delegates, Lambdas, and Events....225
Referencing Methods....226
Delegates....226
Declaring Delegates....226
Using Delegates....227
Passing Delegates to Methods....230
Action and Func Delegates....231
Multicast Delegates....232
Anonymous Methods....234
Lambda Expressions....235
Parameters....235
Multiple Code Lines....236
Closures....236
Events....237
Event Publisher....238
Event Listener....239
Summary....240
Chapter 8 Collections....241
Overview....242
Collection Interfaces and Types....242
Lists....243
Creating Lists....244
Collection Initializers....245
Adding Elements....245
Inserting Elements....246
Accessing Elements....246
Removing Elements....246
Searching....247
Sorting....248
Read-Only Collections....250
Queues....250
Stacks....254
Linked Lists....256
Sorted List....257
Dictionaries....259
Dictionary Initializers....260
Key Type....260
Dictionary Example....261
Lookups....265
Sorted Dictionaries....265
Sets....266
Performance....268
Immutable Collections....270
Using Builders with Immutable Collections....271
Immutable Collection Types and Interfaces....272
Using LINQ with Immutable Arrays....273
Summary....273
Chapter 9 Language Integrated Query....274
LINQ Overview....275
Lists and Entities....275
LINQ Query....277
Extension Methods....278
Deferred Query Execution....279
Standard Query Operators....281
Filter....282
Filter with Index....283
Type Filtering....284
Compound from....284
Sorting....285
Grouping....287
Variables Within the LINQ Query....288
Grouping with Nested Objects....289
Inner Join....290
Left Outer Join....293
Group Join....294
Set Operations....297
Zip....298
Partitioning....299
Aggregate Operators....300
Conversion Operators....302
Generation Operators....303
Parallel LINQ....304
Parallel Queries....304
Cancellation....305
Expression Trees....306
LINQ Providers....309
Summary....310
Chapter 10 Errors and Exceptions....311
Handling Errors....312
Predefined Exception Classes....312
Catching Exceptions....313
Exceptions and Performance....316
Implementing Multiple Catch Blocks....317
Catching Exceptions from Other Code....320
System.Exception Properties....320
Exception Filters....321
Rethrowing Exceptions....321
Naïvely Rethrowing the Exception....323
Changing the Exception....323
Rethrowing the Exception....324
Using Filters to Add Functionality....325
What Happens If an Exception Isn’t Handled?....326
User-Defined Exception Classes....326
Catching the User-Defined Exceptions....327
Throwing the User-Defined Exceptions....329
Defining the User-Defined Exception Classes....332
Caller Information....333
Summary....335
Chapter 11 Tasks and Asynchronous Programming....336
Why Asynchronous Programming Is Important....337
Task-Based Async Pattern....338
Tasks....339
Creating Tasks....340
Calling an Asynchronous Method....340
Using the Awaiter....341
Continuation with Tasks....342
Synchronization Context....342
Using Multiple Asynchronous Methods....343
Calling Asynchronous Methods Sequentially....343
Using ValueTasks....344
Using Combinators....343
Error Handling....345
Handling Exceptions with Asynchronous Methods....346
Handling Exceptions with Multiple Asynchronous Methods....346
Using AggregateException Information....347
Cancellation of async Methods....347
Async Streams....348
Async with Windows Apps....350
Configure Await....351
Switch to the UI Thread....352
Using IAsyncOperation....353
Avoid Blocking Scenarios....353
Summary....354
Chapter 12 Reflection, Metadata, and Source Generators....355
Inspecting Code at Runtime and Dynamic Programming....356
Custom Attributes....356
Writing Custom Attributes....357
Specifying the AttributeUsage Attribute....358
Specifying Attribute Parameters....359
Specifying Optional Attribute Parameters....359
Custom Attribute Example: WhatsNewAttributes....360
The WhatsNewAttributes Library....360
The VectorClass Library....361
Using Reflection....362
The System.Type Class....362
Type Properties....363
Methods....364
The TypeView Example....364
The Assembly Class....366
Getting Details About Types Defined in an Assembly....366
Getting Details About Custom Attributes....367
Completing the WhatsNewAttributes Example....367
Using Dynamic Language Extensions for Reflection....370
Creating the Calculator Library....370
Instantiating a Type Dynamically....371
Invoking a Member with the Reflection API....371
Invoking a Member with the Dynamic Type....372
ExpandoObject....373
Source Generators....375
Hello, World Source Generator....376
Source Generators Using Partial Methods....378
Summary....382
Chapter 13 Managed and Unmanaged Memory....383
Memory....384
Memory Management Under the Hood....384
Value Data Types....384
Reference Data Types....386
Garbage Collection....388
Strong and Weak References....390
Working with Unmanaged Resources....392
Destructors or Finalizers....392
The IDisposable and IAsyncDiposable Interfaces....393
The using Statement and the using Declaration....394
Implementing IDisposable and a Destructor....395
IDisposable and Finalizer Rules....396
Unsafe Code....397
Accessing Memory Directly with Pointers....397
Writing Unsafe Code with the unsafe Keyword....398
Pointer Syntax....399
Casting Pointers to Integer Types....400
Casting Between Pointer Types....401
void Pointers....401
Pointer Arithmetic....401
The sizeof Operator....403
Pointers to Structs: The Pointer Member Access Operator....403
Pointers to Class Members....404
Pointer Example: PointerPlayground....405
Function Pointers....409
Using Pointers to Optimize Performance....410
Creating Stack-BasedArrays....410
QuickArray Example....412
Span....413
Spans Referencing the Managed Heap....413
Spans Referencing the Stack....414
Spans Referencing the Native Heap....414
Span Extension Methods....415
Platform Invoke....416
Calling Native Windows APIs....416
Calling Native Linux APIs....419
Using the Library for Calling Native APIs....421
Summary....421
Part II Libraries....423
Chapter 14 Libraries, Assemblies, Packages, and NuGet....425
The Hell of Libraries....426
Assemblies....427
Creating and Using Libraries....429
.NET Standard....429
Creating a .NET Library....430
Solution Files....431
Referencing Projects....431
Referencing NuGet Packages....432
NuGet Sources....432
Creating NuGet Packages....434
NuGet Packages with the Command Line....434
Supporting Multiple Platforms....435
NuGet Packages with Visual Studio....437
Module Initializers....438
Summary....439
Chapter 15 Dependency Injection and Configuration....440
What Is Dependency Injection?....441
Using the .NET DI Container....441
Using the Host Class....443
Lifetime of Services....444
Singleton and Transient Services....446
Using Scoped Services....448
Using Custom Factories....451
Initialization of Services Using Options....451
Using Configuration Files....453
Configuration with .NET Applications....454
Using IConfiguration....455
Reading Strongly Typed Values....456
Configuration Sources....456
Production and Development Settings....457
User Secrets....458
Azure App Configuration....459
Creating Azure App Configuration....459
Using Azure App Configuration in the Development Environment....460
Dynamic Configuration....462
Production and Staging Settings with Azure App Configuration....463
Feature Flags....463
Using the Azure Key Vault....465
Summary....466
Chapter 16 Diagnostics and Metrics....467
Diagnostics Overview....468
Logging....469
Configuring Providers....472
Filtering....474
Configure Logging....474
Logging and Tracing with OpenTelemetry....475
More Logging Providers....477
Metrics....477
EventSource Class....477
Metric Counters....478
Using MetricsSampleSource....480
Monitoring Metrics with .NET CLI....481
Analytics with Visual Studio App Center....482
Application Insights....485
Summary....487
Chapter 17 Parallel Programming....488
Overview....489
Parallel Class....490
Looping with the Parallel.For Method....491
Stopping Parallel.For Early....493
Parallel.For Initialization....494
Looping with the Parallel.ForEach Method....495
Invoking Multiple Methods with the Parallel.Invoke Method....495
Tasks....496
Starting Tasks....496
Tasks Using the Thread Pool....497
Synchronous Tasks....498
Tasks Using a Separate Thread....498
Results from Tasks....498
Continuation Tasks....499
Task Hierarchies....500
Returning Tasks from Methods....501
Waiting for Tasks....501
Value Tasks....501
Cancellation Framework....503
Cancellation of Parallel.For....503
Cancellation of Tasks....505
Channels....506
Creating Bounded and Unbounded Channels....506
Writing to the Channel....507
Reading from the Channel....508
Async Streaming with the Channel....508
Timers....509
Using the Timer Class....509
WinUI Dispatcher Timer....509
Threading Issues....511
Race Conditions....512
Deadlocks....514
Interlocked....516
Monitor....516
SpinLock....517
WaitHandle....518
Mutex....518
Semaphore....519
Events....521
Barrier....524
ReaderWriterLockSlim....527
Locks with await....529
Summary....532
Chapter 18 Files and Streams....533
Overview....534
Managing the File System....534
Checking Drive Information....535
Working with the Path Class....536
Creating Files and Folders....536
Accessing and Modifying File Properties....538
Using File to Read and Write....539
Iterating Files....540
Working with Streams....541
Working with File Streams....543
Creating a FileStream....544
Getting Stream Information....544
Analyzing Text File Encodings....545
Reading Streams....546
Writing Streams....547
Copying Streams....547
Using Random Access to Streams....548
Using Buffered Streams....550
Using Readers and Writers....551
The StreamReader Class....551
The StreamWriter Class....552
Reading and Writing Binary Files....553
Compressing Files....553
Using the Deflate Stream....554
Using Brotli....555
Zipping Files....555
Watching File Changes....556
JSON Serialization....557
JSON Serialization....558
JSON Deserialization....560
Using JsonDocument....561
JSON Reader....561
JSON Writer....562
Using Files and Streams with the Windows Runtime....563
Windows App Editor....563
Mapping Windows Runtime Types to .NET Types....566
Summary....567
Chapter 19 Networking....568
Overview....569
Working with Utility Classes....569
URIs....570
IPAddress....571
IPHostEntry....572
DNS....572
Configuring Sockets....574
Using Sockets....574
TCP Echo Sample Using Sockets....574
Creating a Listener....576
Communication with Pipelines....578
Implementing a Receiver....580
Using TCP Classes....581
Creating a TCP Listener....581
Creating a TCP Client....583
Using UDP....585
Building a UDP Receiver....585
Creating a UDP Sender....587
Using Multicasts....589
Using Web Servers....590
Configuring Kestrel....591
Startup....592
HTTP Headers....593
The HttpClient Class....596
Making an Asynchronous Get Request....597
Throwing Exceptions from Errors....598
Creating an HttpRequestMessage....599
Passing Headers....599
Accessing the Content....601
Customizing Requests with HttpMessageHandler....601
HttpClient Factory....602
Typed Clients....603
Named Clients....603
Resilient HTTP Requests....604
Summary....605
Chapter 20 Security....606
Elements of Security....607
Verifying User Information....607
Working with the Microsoft Identity Platform....607
Using Microsoft.Identity.Client....608
Using Authentication and Authorization with a Web App....611
Encrypting Data....614
Getting an X.509 Certificate....617
Creating and Verifying a Signature....619
Implementing Secure Data Exchange....621
Ensuring Web Security....624
Encoding....624
Preventing SQL Injection....626
Protecting Against Cross-Site Request Forgery....627
Summary....629
Chapter 21 Entity Framework Core....630
Introducing EF Core....631
Database Providers....631
Creating an Azure SQL Database....631
Creating a Model....632
Creating a Context....633
Conventions, Annotations, and Fluent API....634
Configuring the Context with the DI Provider....635
Creating the Database....636
Deleting the Database....636
Writing to the Database....637
Reading from the Database....637
Updating with Classes....638
Updating with Records....639
Deleting Records....639
Logging and Metrics....640
Creating a Model....641
Creating a Relation....641
Using the Fluent API for Mapping Definitions....642
Using Self-Contained Type Configuration....643
Mapping to Fields....645
Working with Shadow Properties....646
Scaffolding a Model from the Database....648
Migrations....649
Implementing IDesignTimeDbContextFactory....649
Creating Migrations....650
Applying Migrations Programmatically....653
Other Ways to Apply Migrations....654
Working with Queries....654
Basic Queries....654
Asynchronous Streams....657
Raw SQL Queries....657
Compiled Queries....657
Global Query Filters....659
EF.Functions....660
Loading Related Data....660
Eager Loading Related Data....661
Eager Loading with Filtered Include....661
Explicit Loading Related Data....662
Lazy Loading....663
Working with Relationships....665
Many-to-Many Relations....665
Table Splitting....667
Owned Entities....669
Table per Hierarchy....671
Saving Data....673
Adding Objects with Relations....674
Tracking Objects....675
Updating Objects....677
Updating Untracked Objects....677
Conflict Handling....678
The Last One Wins....679
The First One Wins....680
Using Transactions....683
Using Implicit Transactions....683
Creating Explicit Transactions....684
Using Ambient Transactions....685
Using Azure Cosmos DB....687
Summary....691
Chapter 22 Localization....692
Global Markets....693
Namespace System.Globalization....693
Unicode Issues....693
Cultures and Regions....694
Specific, Neutral, and Invariant Cultures....694
Current Culture and Current UI Culture....695
Number Formatting....695
Date Formatting....696
Cultures in Action....697
Sorting....702
Resources....704
Resource Readers and Writers....705
Using Resource Files with ResourceManager....705
Localization with ASP.NET Core....706
Registering Localization Services....707
Configuring the Middleware....707
ASP.NET Core Culture Providers....708
Using a Culture with ASP.NET Core....709
Using Resources with ASP.NET Core....709
Localization with Data Annotations....711
Localization with WINUI....712
Using the MRT ResourceLoader....713
Using the MRT ResourceManager....714
Changing the Language with a ResourceContext....714
Summary....715
Chapter 23 Tests....716
Overview....716
Unit Testing....717
Creating Unit Tests....717
Running Unit Tests....719
Implementing Complex Methods....719
Expecting Exceptions....720
Testing All Code Paths....721
Code Coverage....722
External Dependencies....723
Using a Mocking Library....726
ASP.NET Core Integration Testing....730
Summary....732
Part III Web Applications and Services....733
Chapter 24 ASP.NET Core....735
Understanding Web Technologies....735
HTML....736
CSS....736
JavaScript and TypeScript....736
Scripting Libraries....737
WebAssembly....737
Creating an ASP.NET Core Web Project....737
Host Server....739
Startup....740
Sample Application Preparations....741
Adding Client-Side Content....742
Creating Custom Middleware....744
Endpoint Routing....747
Defining Routes....747
Route Constraints....748
Request and Response....748
Request Headers....749
Query Parameters....751
Form Data....752
Cookies....753
Sending JSON....754
Session State....754
Health Checks....756
Deployment....759
Summary....761
Chapter 25 Services....762
Understanding Today’s Services....763
REST Services with ASP.NET Core....763
Defining a Model....764
Creating a Service....764
Creating a Controller....768
Testing REST APIs....770
REST Results and Status Codes....771
Creating a .NET Client....772
Sending GET Requests....773
Sending POST Requests....776
Sending PUT Requests....776
Sending DELETE Requests....777
Using EF Core with Services....778
Authentication and Authorization with Azure AD B2C....780
Creating and Configuring the Service....782
Adding Authentication to the Client Application....786
Implementing and Using Services with GRPC....788
Creating a gRPC Project....788
Defining the Contract with Protobuf....789
Implementing a gRPC Service....790
Implementing a gRPC Client....792
Streaming with gRPC....794
Using Azure Functions....796
Creating an Azure Functions Project....796
Adding HTTP Trigger Functions....797
More Azure Services....799
Summary....799
Chapter 26 Razor Pages and MVC....800
Setting Up Services for Razor Pages and MVC....801
Creating Razor Pages Projects....801
Understanding Razor Syntax....802
Razor Pages....803
Layouts....803
Passing Data Between Views....805
Render Sections....805
Routing with Parameters....806
Razor Libraries and Areas....808
Injecting Services....809
Returning Results....809
Model Binding....810
Working with HTML Helpers....810
Working with Tag Helpers....811
Validation of User Input....812
Creating Custom Tag Helpers....813
Creating Elements with Tag Helpers....815
View Components....818
ASP.NET Core MVC....821
MVC Bootstrapping....821
MVC Routing....821
Controllers....822
Razor Views....823
Strongly Typed Views....823
Partial Views....824
Identity UI....825
Summary....826
Chapter 27 Blazor....827
Blazor Server and Blazor WebAssembly....828
Blazor Server....828
WebAssembly....828
Blazor WebAssembly....829
Creating a Blazor Server Web Application....830
Blazor Server Startup....830
Blazor Layout....831
Navigation....832
The Counter Component....833
The FetchData Component....834
Blazor WebAssembly....836
Blazor WebAssembly Startup....837
Injecting HttpClient with Blazor WebAssembly....838
Working with Progressive Web Applications....839
Razor Components....840
Understanding the Parameters of Components....840
Injecting Services....841
Working with Event Callback....842
Programmatically Updating the UI....844
Two-Way Binding....844
Cascading Parameters....845
Using Templated Components....846
Using Built-in Components....847
Summary....848
Chapter 28 SignalR....849
Overview....849
Creating a Simple Chat Using SIGNALR....850
Creating a Hub....850
Creating a Client with HTML and JavaScript....852
Creating SignalR .NET Clients....854
Grouping Connections....858
Extending the Hub with Groups....858
Extending the Windows Client App with Groups....859
Streaming with SIGNALR....862
Summary....864
Part IV Apps....865
Chapter 29 Windows Apps....867
Introducing Windows Apps....867
Windows Runtime....869
Hello, Windows....870
Application Manifest....870
Application Startup....870
Main Window....872
Introducing XAML....874
Mapping Elements to Classes....874
Using Custom .NET Classes with XAML....875
Setting Properties as Attributes....876
Using Properties as Elements....877
Dependency Properties....877
Creating a Dependency Property....878
Value Changed Callbacks and Events....879
Routed Events....880
Attached Properties....881
Markup Extensions....883
Custom Markup Extensions....884
Working with Controls....885
FrameworkElement-Derived UI Elements....886
Presenters....888
Control-Derived Controls....888
Using a TextBox....891
Selecting a Date....891
Range Controls....895
Progress Bar....896
Slider....896
Content Controls....897
Buttons....898
Replacing the Content of the Button....898
Linking with the HyperlinkButton....899
Items Controls....899
Flyouts....900
Working with Data Binding....900
Change Notification with INotifyPropertyChanged....901
Creating a List of Books....903
List Binding....904
Binding Events to Methods....904
Using Data Templates and the Data Template Selector....905
Show Lists and Details....906
Binding Simple Objects....907
Value Conversion....908
Implementing Navigation....909
Hub....910
TabView....912
NavigationView....913
Implementing Layout Panels....915
StackPanel....915
Grid....916
VariableSizedWrapGrid....917
RelativePanel....918
Adaptive Triggers....920
Deferred Loading....922
Summary....923
Chapter 30 Patterns with XAML Apps....924
Why MVVM?....924
Defining the MVVM Pattern....925
Sample Solution....927
Models....927
Services....930
View Models....931
IEditableObject....934
Concrete View Model Implementations....935
Commands....936
Services, View Models, and Dependency Injection....937
Views....939
Opening Dialogs from View Models....941
Navigating Between Pages....942
Messaging Using Events....945
Summary....946
Chapter 31 Styling Windows Apps....947
Styling....948
Shapes....948
Geometry....950
Geometries Using Segments....950
Geometries Using Path Markup....951
Transformation....951
Scaling....952
Translating....952
Rotating....953
Skewing....953
Transforming with Groups and Composite Transforms....953
Transforming Using a Matrix....953
Brushes....954
SolidColorBrush....954
Gradient Brushes....955
ImageBrush....955
AcrylicBrush....956
Styles and Resources....956
Styles....956
Resource Hierarchies....958
Theme Resources....959
Templates....961
Control Templates....961
Styling a ListView....963
Item Container Style....965
Items Panel....965
Animations....966
Timeline....966
Easing Functions....968
Keyframe Animations....973
Transitions....974
Reposition Transition....974
Pane Transition....974
Transitions for Items....975
Visual State Manager....976
Predefined States with Control Templates....977
Defining Custom States....978
Setting Custom States....979
Summary....979
Index....981
EULA....1011
In Professional C# and .NET: 2021 Edition, Microsoft MVP for Visual Studio and Development Technologies and veteran developer, Christian Nagel, delivers a comprehensive tour of the new features and capabilities of C#9 and .NET 5.
Experienced programmers making the transition to C# will benefit from the author’s in-depth explorations to create Web- and Windows applications using ASP.NET Core, Blazor, and WinUI using modern application patterns and new features offered by .NET including Microservices deployed to Docker images, GRPC, localization, asynchronous streaming, and much more.
Perfect for programmers with a background in C#, Visual Basic, Java, or C/C++, Professional C# and .NET: 2021 Edition will also earn a place in the libraries of software architects seeking an up-to-date and fulsome treatment of the latest C# and .NET releases.