Read more
Figures xxi Tables xxiii Foreword xxv Preface xxvii Acknowledgments xxxix About the Author xli Chapter 1: Introducing C# 1 Hello, World 2 C# Syntax Fundamentals 7 Working with Variables 14 Console Input and Output 18 Comments 22 Common Intermediate Language and ILDASM 25 Chapter 2: Data Types 29 Fundamental Numeric Types 30 More Fundamental Types 38 null and void 49 Categories of Types 50 Nullable Modifier 53 Conversions between Data Types 53 Arrays 60 Chapter 3: Operators and Control Flow 77 Operators 78 Introducing Flow Control 92 Code Blocks ({}) 99 Scope 101 Boolean Expressions 102 Bitwise Operators (<<, >>, |, &, ^, ~) 108 Control Flow Statements, Continued 113 Jump Statements 124 C# Preprocessor Directives 130 Chapter 4: Methods and Parameters 139 Calling a Method 140 Declaring a Method 146 The using Directive 151 Returns and Parameters on Main() 155 Parameters 158 Recursion 166 Method Overloading 169 Basic Error Handling with Exceptions 171 Chapter 5: Classes 185 Defining and Instantiating a Class 189 Instance Fields 193 Instance Methods 195 Using the this Keyword 196 Access Modifiers 202 Constructors 204 Static 211 const and readonly Modifiers 218 Properties 220 Nested Classes 232 Partial Classes 234 Chapter 6: Inheritance 237 Derivation 238 Overriding the Base Class 250 Abstract Classes 263 Everything Ultimately Derives from System.Object 268 Verifying the Underlying Type with the is Operator 270 Conversion Using the as Operator 271 Chapter 7: Interfaces 273 Introducing Interfaces 274 Polymorphism through Interfaces 275 Interface Implementation 279 Casting between the Implementing Class and Its Interfaces 284 Interface Inheritance 285 Multiple Interface Inheritance 287 Implementing Multiple Inheritance via Interfaces 288 Versioning 291 Interfaces Compared with Classes 293 Chapter 8: Value Types 297 Structs 298 Boxing 305 Enums 311 Chapter 9: Well-Formed Types 323 Overriding object Members 323 Operator Overloading 334 Referencing Other Assemblies 341 Defining Namespaces 346 XML Comments 349 Garbage Collection 353 Resource Cleanup 356 Chapter 10: Exception Handling 365 Multiple Exception Types 365 Catching Exceptions 367 General Catch Block 368 Guidelines for Exception Handling 371 Defining Custom Exceptions 373 Chapter 11: Generics 379 C# without Generics 380 Introducing Generic Types 385 Constraints 396 Generic Methods 409 Generic Internals 413 Chapter 12: Collections 419 Primary Collection Classes 420 Introducing Collection Class Interfaces 433 Providing an Index Operator 444 Returning Null or an Empty Collection 448 Iterators 448 Chapter 13: Delegates and Events 465 Method Pointers 466 Multicast Delegates and the Observer Pattern 482 Events 496 Chapter 14: Reflection and Attributes 509 Reflection 510 Attributes 520 Chapter 15: Multithreading 549 Running and Controlling a Separate Thread 552 Passing Parameters to Threads 557 Thread Pooling 561 Unhandled Exceptions 563 Synchronization 565 Timers 584 Chapter 16: Multithreading Patterns 591 Asynchronous Results Pattern 592 Background Worker Pattern 606 Windows Forms 611 Chapter 17: Platform Interoperability and Unsafe Code 615 Platform Invoke 616 Pointers and Addresses 630 Chapter 18: The Common Language Infrastructure 641 Defining the Common Language Infrastructure (CLI) 642 CLI Implementations 643 C# Compilation to Machine Code 644 Runtime ...