| Acknowledgments | xv |
| Introduction | xvii |
Part I | The .NET Environment and C# | |
Chapter 1 | Introduction to C# and .NET | 2 |
| When to Use C# and C++ | 8 |
| Distinguishing .NET from Other Environments | 11 |
| Using the Common Language Runtime | 13 |
| Viewing Intermediate Language Code | 16 |
| Taking Advantage of Just-In-Time Debugging | 18 |
| Exploiting the .NET Interoperability with COM | 20 |
| Using .NET Versioning to Handle Software Updates | 22 |
| Querying Class Capabilities Through .NET Reflection | 24 |
Chapter 2 | Developing C# Applications Within Visual Studio .NET | 28 |
| Using the Visual Studio Options Dialog Box | 34 |
| Customizing Toolbars and Menus | 35 |
| Adding Items to the Tools Menu | 38 |
| Test Driving Visual Studio .NET | 41 |
| Using the Properties Tool Window | 46 |
| Using IntelliSense | 47 |
| Getting Help | 49 |
Part II | The C# Language | |
Chapter 3 | Getting Started with C# | 54 |
| Accessing C# Library Classes | 60 |
| Creating a Command Line Program | 61 |
| Adding References to a Command Line Program | 64 |
| Comparing the Results with C++ | 65 |
| Creating a Windows Program | 66 |
| Comparing the Results with Visual Basic | 68 |
| Understanding White Space and Tokens | 71 |
| Commenting Your Code | 72 |
| Documenting Your Code with XML Comments | 75 |
| Using the C# Debugger | 75 |
| Using the Output and Task List Windows | 78 |
| Deciphering the Task List Window | 79 |
| Writing and Using Your Own Namespaces | 80 |
| Using the Console Class | 81 |
| Formatting Output and Strings | 83 |
| Using Preprocessor Directives | 87 |
Chapter 4 | Laying a C# Foundation | 90 |
| Understanding Value Types | 98 |
| Understanding References | 98 |
| Writing Expressions | 102 |
| Writing Statements | 103 |
| Using Managed Code | 104 |
| Using Logical Operators | 107 |
| Using Relational, Equality, and Conditional Operators | 110 |
| Using Assignment Operators | 113 |
| Understanding C# Type Operators | 116 |
| Using unsafe Code | 117 |
| Using the sizeof Operator | 120 |
| Boxing and Unboxing | 121 |
| Using checked and unchecked Statements | 124 |
| Writing Loops | 128 |
| Using Program Control Statements | 132 |
| Understanding Scope in C# | 138 |
Chapter 5 | Data Types in C# | 142 |
| Defining Structures Within C# | 148 |
| Declaring and Using Simple Data Types | 150 |
| Creating Enumerated Lists | 152 |
| Using Reference Types | 155 |
| Basics of C# Classes | 156 |
| Declaring Arrays in C# | 157 |
| Understanding Interfaces | 158 |
| Using Delegates to Create a Callback Function | 160 |
| Using the object Data Type | 162 |
| Passing Variables to Functions | 164 |
| Using Fields and Properties | 166 |
| Using String Interning to Reduce Memory Consumption | 171 |
| Encoding Strings in C# | 172 |
| Data Conversion in C# | 176 |
Chapter 6 | Structures in C# | 178 |
| Defining Structures | 183 |
| Using Structures as Value-Type Objects | 187 |
| Using Structures as References | 188 |
| Adding Functions to Structures | 190 |
| Adding Properties to a Structure | 194 |
Chapter 7 | Understanding C# Classes | 200 |
| Taking Advantage of Built-In Classes | 205 |
| Referring to the Current Object Using the this Keyword | 213 |
| Protecting Class Members Using Access Keywords | 215 |
| Using Class Member Methods and Properties | 217 |
| Using the static Modifier with Class Members | 223 |
| Declaring Constructors and Destructors | 225 |
| Creating Constants and readonly Fields | 231 |
| Nesting One Class Within Another | 235 |
| Overloading and Name Hiding | 238 |
Chapter 8 | Object-Oriented Programming and C# | 246 |
| Encapsulating Your Data | 249 |
| Inheriting from a Base Class | 251 |
| Designing a Base Class | 255 |
| Hiding Base Class Members | 256 |
| Calling Constructors and Destructors in Order | 258 |
| Preventing Inheritance--The Sealed Modifier | 260 |
| Polymorphism: Changing Class Behavior Using Virtual Methods | 261 |
| Using Virtual Properties | 273 |
| Defining an Abstract Class | 275 |
| Declaring an Abstract Function | 276 |
| Using the Object Browser | 279 |
| Setting the Browsing Scope | 280 |
| Using the Objects Pane | 281 |
| Using the Members Pane | 282 |
| Navigating the Object Browser | 283 |
| Searching for Symbols | 284 |
Chapter 9 | Handling Exceptions | 286 |
| Using Exception Handling in the CLR | 290 |
| Using try and catch Blocks | 292 |
| Catching an Exception | 295 |
| Using Multiple catch Blocks | 298 |
| Using the Exception Classes | 300 |
| Throwing an Exception | 303 |
| Scope in Exception Blocks | 308 |
| Using Exceptions with checked Variables | 309 |
| Terminating a Program in an Exception Block | 311 |
| Understanding the finally Block | 313 |
Chapter 10 | Advanced C# Concepts | 316 |
| Nesting Namespaces | 321 |
| Specifying Namespaces with the using Directive | 323 |
| Taking a Closer Look at the using Statement | 326 |
| Adding References | 327 |
| Building a Module File | 331 |
| Creating a Shared Assembly | 332 |
| Using C# Interfaces to Define an Abstraction | 336 |
| Getting Runtime Information Using Reflection | 340 |
| Dynamically Invoking an Object | 344 |
| Creating Threads of Execution | 346 |
Chapter 11 | Using Arrays | 352 |
| Initializing an Array | 358 |
| Using Multi-Dimensional Arrays | 360 |
| Using Jagged Arrays | 364 |
| Using the System.Array Class | 366 |
| Searching and Sorting Arrays | 368 |
| Using the Copy Method to Copy Array Values | 370 |
| Using Arrays of Objects | 373 |
| Using Indexers | 376 |
| How Indexers Work | 377 |
| Declaring an Indexer | 378 |
| Using the C# Indexer Wizard | 379 |
Chapter 12 | File Operations | 382 |
| Using the FileStream Class | 389 |
| Using the MemoryStream Class to Create Temporary Storage | 392 |
| Using the NetworkStream Class to Create a Network Connection | 395 |
| Using the BufferedStream Class to Buffer a Stream's Input or Output | 399 |
| Performing Asynchronous I/O | 401 |
| Discarding Unnecessary Data Using the Null Field as a Bit Bucket | 404 |
| Exploiting the TextReader and TextWriter Abstract Classes | 405 |
| Using StreamReader and StreamWriter | 406 |
| Opening a File Using the FileOpen Common Dialog | 410 |
| Using the File and FileInfo classes | 414 |
| Getting and Setting the Directory | 418 |
Part III | Windows Programming in C# | |
Chapter 13 | Writing Windows Forms Applications | 424 |
| Creating a Form-Based Application | 429 |
| Hiding and Showing Forms | 432 |
| Adding Controls to a Form | 435 |
| Adding Forms to an Application | 439 |
| Setting the Tab Order | 444 |
| Setting Form Properties | 445 |
| Using Modal and Modeless Forms | 446 |
Chapter 14 | Debugging C# Programs | 454 |
| Debugging C# and .NET Applications Using DbgCLR.exe | 459 |
| Troubleshooting .NET Applications Using Just-In-Time Debugging | 462 |
| Running a Program in the Visual Studio Debugger | 463 |
| Setting Breakpoints to Suspend a Program's Execution | 465 |
| Setting Conditions on Methods | 467 |
| Recovering the StackTrace | 470 |
| Using the Debug Class | 472 |
| Using Trace Listeners | 477 |
| Writing Messages to Event Logs | 482 |
Chapter 15 | Building the User Interface | 488 |
| Adding a Menu to a Form | 490 |
| Using the Menu Designer | 494 |
| Adding Menu Adornments | 501 |
| Adding Shortcut Keys (Accelerators) | 502 |
| Adding Images | 503 |
| Adding a Toolbar | 504 |
| Adding a Context Menu | 506 |
| Displaying Items in a TreeView Control | 507 |
| Displaying Items in a ListView Control | 513 |
| An Explorer-Style Application | 520 |
Chapter 16 | Using Windows Controls | 524 |
| Setting Properties for Controls | 529 |
| Using Invisible Controls | 533 |
| Responding to Control Messages | 534 |
| Using One Event for Multiple Controls | 536 |
| Enabling and Disabling Controls Using Idle Processing | 538 |
| Using the GroupBox Control | 540 |
| Grouping Radio Button Controls | 542 |
| Anchoring Controls on Forms | 544 |
| Docking Controls on Forms | 545 |
Chapter 17 | Using the Common Dialogs | 548 |
| Choosing a Color | 551 |
| Selecting a Text Style with FontDialog | 555 |
| Opening and Saving Files | 557 |
| A Word About Printing | 560 |
| Selecting a Printer | 566 |
| Setting Page Options | 568 |
| Previewing the Print Output | 570 |
Chapter 18 | Using Events and Delegates | 572 |
| Using Events Within C# Programs | 577 |
| Writing an Event Handler | 579 |
| Sorting Objects Using a Delegate | 581 |
| Using a static Delegate | 587 |
| Viewing a Delegate's Invocation List | 589 |
| Combining and Removing Delegate Methods | 591 |
| Responding to Timer Events | 593 |
| Responding to System.Threading.Timer Events | 595 |
| Index | 599 |