HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
The Comprehensive, Expert Guide to C# 8.0 for Programmers at All Levels
"Welcome to one of the most venerable and trusted franchises you could dream of in the world of C# books -- and probably far beyond! . . . Mark is super smart, insists on understanding everything to the core, and has phenomenal insight into how things affect real developers. . . . He goes right to the essence and communicates with great integrity -- no sugarcoating -- and has a keen eye for practical value and real-world problems."
-- From the Foreword by Mads Torgersen, C# Lead Designer, Microsoft
Essential C# 8.0 is a well-organized, no-fluff guide to C# 8.0 for programmers at all levels of experience. This edition retains all the valuable content of prior editions and adds discussions of null reference types, indices and ranges, enhanced pattern matching, asynchronous stream, and more.
World-class C# expert Mark Michaelis presents a comprehensive tutorial and reference for the entire language, providing an accelerated learning opportunity to achieve expert C# programming skills. He includes key C# 8.0 enhancements, succinct examples to illustrate central constructs, and updated coding guidelines for minimizing bugs and writing code that's easier to evolve. To help you quickly find what you need, there are version-specific indexes of C# 6.0, 7.0, and 8.0 topics and visual icons that identify when each language innovation was introduced.
Download the sample pages (includes Chapter 5)
Figures xvii
Tables xix
Foreword xxi
Preface xxiii
Acknowledgments xxxv
About the Author xxxvii
Chapter 1: Introducing C# 1
Hello, World 2
C# Syntax Fundamentals 13
Working with Variables 22
Console Input and Output 26
Managed Execution and the Common Language Infrastructure 34
Multiple .NET Frameworks 39
Chapter 2: Data Types 45
Fundamental Numeric Types 46
More Fundamental Types 55
Conversions between Data Types 72
Chapter 3: More with Data Types 81
Categories of Types 81
Declaring Types That Allow null 84
Implicitly Typed Local Variables 89
Tuples 92
Arrays 98
Chapter 4: Operators and Flow Control 121
Operators 122
Introducing Flow Control 138
Code Blocks ({}) 144
Code Blocks, Scopes, and Declaration Spaces 147
Boolean Expressions 149
Programming with null 155
Bitwise Operators (<<, >>, |, &, ^, ~) 162
Control Flow Statements, Continued 168
Jump Statements 180
C# Preprocessor Directives 186
Summary 193
Chapter 5: Methods and Parameters 195
Calling a Method 196
Declaring a Method 203
The using Directive 209
Returns and Parameters on Main() 214
Advanced Method Parameters 217
Recursion 229
Method Overloading 231
Optional Parameters 234
Basic Error Handling with Exceptions 239
Summary 253
Chapter 6: Classes 255
Declaring and Instantiating a Class 259
Instance Fields 262
Instance Methods 265
Using the this Keyword 266
Access Modifiers 274
Properties 276
Constructors 293
Non-Nullable Reference Type Properties with Constructors 303
Nullable Attributes 306
Deconstructors 309
Static Members 311
Extension Methods 321
Encapsulating the Data 323
Nested Classes 326
Partial Classes 329
Summary 333
Chapter 7: Inheritance 335
Derivation 336
Overriding the Base Class 346
Abstract Classes 357
All Classes Derive from System.Object 363
Pattern Matching with the is Operator 365
Pattern Matching within a switch Expression 371
Avoid Pattern Matching When Polymorphism Is Possible 373
Summary 374
Chapter 8: Interfaces 377
Introducing Interfaces 378
Polymorphism through Interfaces 380
Interface Implementation 384
Converting between the Implementing Class and Its Interfaces 390
Interface Inheritance 390
Multiple Interface Inheritance 393
Extension Methods on Interfaces 394
Versioning 396
Extension Methods versus Default Interface Members 411
Interfaces Compared with Abstract Classes 413
Interfaces Compared with Attributes 415
Chapter 9: Value Types 417
Structs 422
Boxing 428
Enums 437
Summary 447
Chapter 10: Well-Formed Types 451
Overriding object Members 451
Operator Overloading 464
Referencing Other Assemblies 472
Encapsulation of Types 479
Defining Namespaces 481
XML Comments 485
Garbage Collection 489
Resource Cleanup 493
Lazy Initialization 508
Summary 510
Chapter 11: Exception Handling 511
Multiple Exception Types 511
Catching Exceptions 514
Rethrowing an Existing Exception 517
General Catch Block 518
Guidelines for Exception Handling 519
Defining Custom Exceptions 523
Rethrowing a Wrapped Exception 527
Summary 530
Chapter 12: Generics 533
C# without Generics 534
Introducing Generic Types 539
Constraints 553
Generic Methods 568
Covariance and Contravariance 573
Generic Internals 580
Summary 585
Chapter 13: Delegates and Lambda Expressions 587
Introducing Delegates 588
Declaring Delegate Types 592
Lambda Expressions 600
Statement Lambdas 601
Anonymous Methods 606
Delegates Do Not Have Structural Equality 608
Outer Variables 611
Expression Trees 616
Summary 623
Chapter 14: Events 625
Coding the Publish–Subscribe Pattern with Multicast Delegates 626
Understanding Events 641
Summary 651
Chapter 15: Collection Interfaces with Standard Query Operators 653
Collection Initializers 654
What Makes a Class a Collection: IEnumerable 657
Standard Query Operators 663
Anonymous Types with LINQ 695
Summary 704
Chapter 16: LINQ with Query Expressions 705
Introducing Query Expressions 706
Query Expressions Are Just Method Invocations 724
Summary 726
Chapter 17: Building Custom Collections 727
More Collection Interfaces 728
Primary Collection Classes 731
Providing an Indexer 750
Returning null or an Empty Collection 753
Iterators 753
Summary 768
Chapter 18: Reflection, Attributes, and Dynamic Programming 769
Reflection 770
nameof Operator 781
Attributes 783
Programming with Dynamic Objects 800
Summary 811
Chapter 19: Introducing Multithreading 813
Multithreading Basics 815
Asynchronous Tasks 822
Canceling a Task 843
Working with System.Threading 850
Summary 851
Chapter 20: Programming the Task-Based Asynchronous Pattern 853
Synchronously Invoking a High-Latency Operation 854
Asynchronously Invoking a High-Latency Operation Using the TPL 856
The Task-Based Asynchronous Pattern with async and await 861
Introducing Asynchronous Return of ValueTask<T> 867
Asynchronous Streams 870
IAsyncDisposable and the await using Declaration and Statement 874
Using LINQ with IAsyncEnumerable 875
Returning void from an Asynchronous Method 877
Asynchronous Lambdas and Local Functions 881
Task Schedulers and the Synchronization Context 887
async/await with the Windows UI 890
Summary 893
Chapter 21: Iterating in Parallel 895
Executing Loop Iterations in Parallel 895
Running LINQ Queries in Parallel 905
Summary 911
Chapter 22: Thread Synchronization 913
Why Synchronization? 914
Timers 943
Summary 945
Chapter 23: Platform Interoperability and Unsafe Code 947
Platform Invoke 948
Pointers and Addresses 960
Executing Unsafe Code via a Delegate 971
Summary 972
Chapter 24: The Common Language Infrastructure 973
Defining the Common Language Infrastructure 974
CLI Implementations 975
.NET Standard 978
Base Class Library 979
C# Compilation to Machine Code 979
Runtime 982
Assemblies, Manifests, and Modules 986
Common Intermediate Language 989
Common Type System 990
Common Language Specification 991
Metadata 991
.NET Native and Ahead of Time Compilation 993
Summary 993
Index 995
Index of 8.0 Topics 1039
Index of 7.0 Topics 1041
Index of 6.0 Topics 1043