Figures xv Tables xvii Foreword xix Preface xxiii Acknowledgments xxxv About the Authors xxxvii Chapter 1: Introducing C# 1 Hello, World 2 C# Syntax Fundamentals 4 Console Input and Output 18 Chapter 2: Data Types 35 Fundamental Numeric Types 36 More Fundamental Types 45 null and void 58 Categories of Types 61 Nullable Modifier 64 Conversions between Data Types 65 Arrays 71 Chapter 3: Operators and Control Flow 89 Operators 90 Introducing Flow Control 107 Code Blocks ({}) 114 Code Blocks, Scopes, and Declaration Spaces 116 Boolean Expressions 118 Bitwise Operators (>, , &, ^, ~) 128 Control Flow Statements, Continued 134 Jump Statements 146 C# Preprocessor Directives 152 Chapter 4: Methods and Parameters 161 Calling a Method 162 Declaring a Method 169 The using Directive 175 Returns and Parameters on Main() 180 Advanced Method Parameters 183 Recursion 192 Method Overloading 194 Optional Parameters 197 Basic Error Handling with Exceptions 202 Chapter 5: Classes 217 Declaring and Instantiating a Class 221 Instance Fields 225 Instance Methods 227 Using the this Keyword 228 Access Modifiers 235 Properties 237 Constructors 254 Static Members 265 Extension Methods 275 Encapsulating the Data 277 Nested Classes 281 Partial Classes 284 Chapter 6: Inheritance 289 Derivation 290 Overriding the Base Class 302 Abstract Classes 314 All Classes Derive from System.Object 320 Verifying the Underlying Type with the is Operator 321 Conversion Using the as Operator 322 Chapter 7: Interfaces 325 Introducing Interfaces 326 Polymorphism through Interfaces 327 Interface Implementation 332 Converting between the Implementing Class and Its Interfaces 338 Interface Inheritance 338 Multiple Interface Inheritance 341 Extension Methods on Interfaces 341 Implementing Multiple Inheritance via Interfaces 343 Versioning 346 Interfaces Compared with Classes 347 Interfaces Compared with Attributes 349 Chapter 8: Value Types 351 Structs 355 Boxing 362 Enums 371 Chapter 9: Well-Formed Types 383 Overriding object Members 383 Operator Overloading 395 Referencing Other Assemblies 403 Defining Namespaces 409 XML Comments 413 Garbage Collection 418 Resource Cleanup 421 Lazy Initialization 429 Chapter 10: Exception Handling 433 Multiple Exception Types 433 Catching Exceptions 436 General Catch Block 440 Guidelines for Exception Handling 443 Defining Custom Exceptions 446 Rethrowing a Wrapped Exception 449 Chapter 11: Generics 455 C# without Generics 456 Introducing Generic Types 461 Constraints 473 Generic Methods 486 Covariance and Contravariance 491 Generic Internals 498 Chapter 12: Delegates and Lambda Expressions 505 Introducing Delegates 506 Lambda Expressions 516 Anonymous Methods 522 General-Purpose Delegates: System.Func and System.Action 524 Chapter 13: Events 543 Coding the Observer Pattern with Multicast Delegates 544 Events 558 Chapter 14: Collection Interfaces with Standard Query Operators 571 Anonymous Types and Implicitly Typed Local Variables 572 Collection Initializers 578 What Makes a Class a Collection: IEnumerable 582 Standard Query Operators 588 Chapter 15: LINQ with Query Expressions 621 Introducing Query Expressions 622 Query Expressions Are Just Method Invocations 640 Chapter 16: Building Custom Collections 643 More Collection Interfaces 644 Primary Collection Classes 646 Providing an Indexer 663 Returning Null or an Empty Collection 666 Iterators 667 Chapter 17: Reflection, Attributes, and Dynamic Programming 683 Reflection 684 nameof Operator 694 Attributes 696 Programming with Dynamic Objects 719 Chapter 18: Multithreading 731 Multithreading Basics 734 Working with System.Threading 741 Asynchronous Tasks 749 Canceling a Task 768 The Task-Based Asynchronous Pattern 775 Executing Loop Iterations in Parallel 798 Running LINQ Queries in Parallel 809 Chapter 19: Thread Synchronization 815 Why Synchronization? 817 Timers 845 Chapter 20: Platform Interoperability and Unsafe Code 849 Platform Invoke 850 Pointers and Addresses 862 Executing Unsafe Code via a Delegate 872 Using the Windows Runtime Libraries from C# 873 Chapter 21: The Common Language Infrastructure 877 Defining the Common Language Infrastructure 878 CLI Implementations 879 C# Compilation to Machine Code 879 Runtime 883 Application Domains 888 Assemblies, Manifests, and Modules 888 Common Intermediate Language 891 Common Type System 892 Common Language Specification 893 Base Class Library 893 Metadata 894 Appendix A: Downloading and Installing the C# Compiler and CLI Platform 897 Microsoft''s .NET 897 Appendix B: Tic-Tac-Toe Source Code Listing 903 Index 909 Index of 6.0 Topics 953 Index of 5.0 Topics 955 Index of 4.
0 Topics 959 Index of 3.0 Topics 965.