| Acknowledgments | xv |
| Introduction | xvii |
| PART 1 INTRODUCING MICROSOFT VISUAL C# AND VISUAL STUDIO .NET | |
| CHAPTER 1 Welcome to C# | 3 |
| Beginning Programming with the Visual Studio .NET Environment | 4 |
| Writing Your First Program | 7 |
| Using Namespaces | 11 |
| Creating Documentation Using XML and Comments | 14 |
| Creating a Windows Forms Application | 18 |
| CHAPTER 2 Working with Variables, Operators, and Expressions | 27 |
| Understanding Statements | 27 |
| Using Identifiers | 28 |
| Identifying Keywords | 28 |
| Using Variables | 29 |
| Naming Variables | 29 |
| Declaring Variables | 30 |
| Working with Primitive Data Types | 31 |
| Displaying Primitive Data Type Values | 32 |
| Setting Arithmetic Operators | 35 |
| Determining an Operator's Values | 35 |
| Examining Arithmetic Operators | 36 |
| Controlling Precedence | 39 |
| Using Associativity to Evaluate Expressions | 40 |
| Incrementing and Decrementing Variables | 40 |
| CHAPTER 3 Writing Methods and Applying Scope | 43 |
| Declaring Methods | 43 |
| Specifying the Method Declaration Syntax | 44 |
| Writing return Statements | 45 |
| Calling Methods | 47 |
| Specifying the Method Call Syntax | 47 |
| Understanding Scope | 48 |
| Creating Local Scope with a Method | 49 |
| Creating Class Scope with a Class | 49 |
| Overloading Identifiers | 50 |
| Writing and Calling Methods | 51 |
| CHAPTER 4 Using Decision Statements | 59 |
| Declaring bool Variables | 59 |
| Using Boolean Operators | 60 |
| Understanding Equality and Relational Operators | 60 |
| Understanding Logical Operators | 61 |
| Summarizing Operator Precedence and Associativity | 62 |
| Executing if Statements | 62 |
| Understanding if Statement Syntax | 63 |
| Using Blocks to Group Statements | 64 |
| Cascading if Statements | 64 |
| Using switch Statements | 67 |
| Understanding switch Statement Syntax | 68 |
| Following the switch Statement Rules | 69 |
| CHAPTER 5 Using Iteration Statements | 73 |
| Using Compound Assignment Operators | 73 |
| Writing while Statements | 75 |
| Writing for Statements | 76 |
| Understanding for Statement Scope | 77 |
| Writing do Statements | 77 |
| CHAPTER 6 Managing Errors and Exceptions | 93 |
| Coping with Errors | 93 |
| Trying Code and Catching Exceptions | 94 |
| Using Multiple catch Handlers | 95 |
| Writing a General catch Handler | 96 |
| Using Checked and Unchecked Integer Arithmetic | 100 |
| Writing checked Statements | 100 |
| Writing Checked Expressions | 101 |
| Throwing Exceptions | 104 |
| Writing a finally Block | 109 |
| PART 2 UNDERSTANDING THE C# LANGUAGE | |
| CHAPTER 7 Creating and Managing Classes and Objects | 115 |
| What Is Classification? | 115 |
| What Is Encapsulation? | 116 |
| Controlling Accessibility | 117 |
| Working with Constructors and the new Keyword | 119 |
| Overloading Constructors | 121 |
| Understanding static Methods and Data | 128 |
| Creating a Shared Field | 129 |
| Creating a static Field with the const Keyword | 130 |
| CHAPTER 8 Understanding Values and References | 135 |
| Copying int Variables and Classes | 135 |
| Using ref and out Parameters | 139 |
| Creating ref Parameters | 140 |
| Creating out Parameters | 141 |
| What Are the Stack and the Heap? | 143 |
| Using the Stack and the Heap | 143 |
| What Is System.Object? | 144 |
| Boxing | 146 |
| Unboxing | 146 |
| Pointers and Unsafe Code | 148 |
| CHAPTER 9 Creating Value Types with Enumerations and Structs | 153 |
| Working with Enumerations | 153 |
| Declaring an Enumeration Type | 154 |
| Choosing Enumeration Literal Values | 154 |
| Choosing an Enumeration's Underlying Type | 154 |
| Using an Enumeration | 155 |
| Working with Struct Types | 157 |
| Declaring Struct Types | 158 |
| Understanding Struct and Class Differences | 158 |
| Declaring Struct Variables | 160 |
| Understanding Struct Definite Assignment | 161 |
| Calling Struct Constructors | 162 |
| Copying Struct Variables | 163 |
| Understanding Keyword-Type Equivalences | 164 |
| CHAPTER 10 Using Arrays and Collections | 171 |
| What Is an Array? | 171 |
| Declaring Array Variables | 171 |
| Creating Array Instances | 172 |
| Initializing Array Variables | 173 |
| Accessing Individual Array Elements | 174 |
| Iterating Through an Array | 175 |
| Copying Arrays | 176 |
| Using the System.Array Class | 178 |
| What Are Collection Classes? | 179 |
| ArrayList | 180 |
| Queue | 182 |
| Stack | 183 |
| SortedList | 184 |
| Comparing Arrays and Collections | 186 |
| Using Collection Classes to Play Cards | 186 |
| CHAPTER 11 Understanding Parameter Arrays | 193 |
| Creating Overloaded Methods | 193 |
| Using Array Arguments | 194 |
| Declaring params Arrays | 195 |
| Using params object[ ] | 198 |
| Using params Arrays | 200 |
| Using the Main Method | 204 |
| CHAPTER 12 Working with Inheritance | 207 |
| What Is Inheritance? | 207 |
| Understanding Core Syntax | 208 |
| Base Classes and Derived Classes | 208 |
| Calling Base Class Constructors | 209 |
| new Methods | 210 |
| virtual Methods | 211 |
| override Methods | 212 |
| protected Access | 213 |
| Creating Interfaces | 214 |
| Syntax | 215 |
| Restrictions | 215 |
| Implementing an Interface | 216 |
| Abstract Classes | 217 |
| Sealed Classes | 220 |
| Sealed Methods | 220 |
| Extending an Inheritance Hierarchy | 220 |
| Working with Multiple Interfaces | 226 |
| Syntax | 226 |
| Explicit Interface Implementation | 226 |
| Summarizing Keyword Combinations | 228 |
| CHAPTER 13 Using Garbage Collection and Resource Management | 231 |
| Garbage Collection | 231 |
| Comparing Values and Objects | 231 |
| The Life and Times of an Object | 232 |
| Writing Destructors | 233 |
| Why Use the Garbage Collector? | 234 |
| How Does the Garbage Collector Run? | 235 |
| Recommendations | 236 |
| Resource Management | 236 |
| The Disposal Method Pattern | 236 |
| Exception-Safe Disposal | 237 |
| The using Statement | 238 |
| Adapting to IDisposable | 239 |
| Calling a Disposal Method from a Destructor | 240 |
| Making Code Exception-Safe | 242 |
| PART 3 CREATING COMPONENTS | |
| CHAPTER 14 Implementing Properties to Access Attributes | 249 |
| Comparing Fields and Methods | 249 |
| What Are Properties? | 251 |
| get Accessors | 252 |
| set Accessors | 252 |
| Read/Write Properties | 253 |
| Read-Only Properties | 253 |
| Write-Only Properties | 254 |
| Understanding the Property Restrictions | 254 |
| Using Static Properties | 255 |
| Declaring Interface Properties | 257 |
| Using Properties in a Windows Application | 258 |
| CHAPTER 15 Using Indexers | 265 |
| What Is an Indexer? | 265 |
| An Example That Doesn't Use Indexers | 265 |
| The Same Example Using Indexers | 267 |
| get Accessors | 269 |
| set Accessors | 269 |
| Read/Write Indexers | 269 |
| Read-Only Indexers | 270 |
| Write-Only Indexers | 270 |
| Comparing Indexers and Methods | 271 |
| Comparing Indexers and Arrays | 271 |
| Comparing Indexers and Properties | 272 |
| Interface Indexers | 272 |
| Using Indexers in a Windows Application | 273 |
| CHAPTER 16 Delegates and Events | 281 |
| Using Delegate Declarations and Instances | 281 |
| An Example That Doesn't Use a Delegate | 281 |
| The Same Example Using a Delegate | 284 |
| Declaring a Delegate | 284 |
| Calling a Delegate | 285 |
| Creating a Delegate Instance | 286 |
| Using Delegates | 288 |
| Enabling Notifications with Events | 290 |
| Declaring an Event | 291 |
| Subscribing to an Event | 291 |
| Unsubscribing from an Event | 292 |
| Calling an Event | 292 |
| Understanding GUI Events | 293 |
| Using Events | 295 |
| CHAPTER 17 Operator Overloading | 301 |
| Working with Operators | 301 |
| Understanding Operators | 301 |
| Implementing Operator Constraints | 302 |
| Overloaded Operators | 303 |
| Creating Symmetric Operators | 304 |
| Understanding Compound Assignment | 306 |
| Declaring Increment and Decrement Operators | 307 |
| Using Operator Pairs | 308 |
| Implementing an Operator | 309 |
| Declaring Conversion Operators | 312 |
| Providing Built-In Conversions | 312 |
| Declaring User-Defined Conversion Operators | 312 |
| Creating Symmetric Operators (Again) | 313 |
| Adding an Implicit Conversion Operator | 314 |
| PART 4 WORKING WITH WINDOWS APPLICATIONS | |
| CHAPTER 18 Introducing Windows Forms | 319 |
| Creating Your Application | 320 |
| Creating a Windows Forms Application | 320 |
| What Are the Common Windows Forms Properties? | 324 |
| Changing Properties Programmatically | 326 |
| Adding Controls to the Form | 327 |
| Using Windows Forms Controls | 327 |
| Setting Control Properties | 329 |
| Changing Properties Dynamically | 332 |
| Publishing Events in Windows Forms | 335 |
| Processing Events in Windows Forms | 335 |
| CHAPTER 19 Working with Menus | 341 |
| Menu Guidelines and Style | 341 |
| Adding Menus and Processing Menu Events | 342 |
| Creating a Menu | 342 |
| Setting Menu Item Properties | 344 |
| Other Menu Item Properties | 347 |
| Menu Events | 348 |
| Pop-Up Menus | 350 |
| Creating Pop-Up Menus | 350 |
| CHAPTER 20 Performing Validation | 357 |
| Validating Data | 357 |
| The CausesValidation Property | 358 |
| Validation Events | 358 |
| An ExampleCustomer Maintenance | 358 |
| Performing Validation with a Sledge Hammer | 359 |
| Being Unobtrusive | 363 |
| Using an ErrorProvider Control | 366 |
| CHAPTER 21 Using Complex Controls | 371 |
| The Explorer Interface | 371 |
| Splitter Windows, Docking Controls, and Panels | 373 |
| Working with the Splitter and Docked Controls | 373 |
| Using a Panel | 376 |
| Docking the Controls | 376 |
| Controls for Navigating Data | 377 |
| Working with the TreeView Control | 378 |
| Using a ListView Control | 386 |
| CHAPTER 22 Using the MDI, Windows, and Dialog Boxes | 397 |
| What Is the Multiple Document Interface? | 398 |
| Building an MDI Application | 398 |
| Alternatives to MDI | 404 |
| Creating Dialog Boxes | 405 |
| Displaying Modal and Modeless Dialog Boxes | 405 |
| Using Common Dialog Controls | 409 |
| Using the SaveFileDialog Control | 409 |
| CHAPTER 23 Creating GUI Components | 415 |
| Working with User Controls | 415 |
| Building the Login User Control | 416 |
| Using the Login User Control | 423 |
| Specializing Controls Using Subclassing | 426 |
| Creating a ToggleButton Control | 427 |
| Using the ToggleButton Control | 431 |
| PART 5 MANAGING DATA | |
| CHAPTER 24 Using a Database | 437 |
| Using ADO.NET Databases | 437 |
| Using the Northwind Traders Database | 438 |
| Accessing the Database | 439 |
| Using ADO.NET Programmatically | 448 |
| CHAPTER 25 Working with Data Binding and DataSets | 459 |
| Windows Forms Controls and Data Binding | 460 |
| Using Simple Data Binding | 460 |
| Using Complex Data Binding | 464 |
| Disconnected DataSets | 468 |
| Creating a Disconnected DataSet | 468 |
| Handling Updates with a Disconnected DataSet | 472 |
| CHAPTER 26 Handling XML | 479 |
| Why XML? | 479 |
| The Goals of XML | 480 |
| The Structure of XML | 480 |
| XML Schemas | 481 |
| XML as a Transport Format and Protocol | 483 |
| XML APIs and the .NET Framework | 483 |
| The Employee Timesheet System | 484 |
| Creating an XML Schema | 484 |
| Building the Timesheet Recording Application | 490 |
| Creating the Timesheet Analysis Application | 494 |
| PART 6 BUILDING WEB APPLICATIONS | |
| CHAPTER 27 Introducing ASP.NET | 501 |
| Understanding the Internet as an Infrastructure | 502 |
| Understanding Web Server Requests and Responses | 502 |
| Managing State | 503 |
| Understanding ASP .NET | 504 |
| Creating Web Applications with ASP .NET | 505 |
| Building an ASP .NET Application | 505 |
| Understanding Server Controls | 514 |
| CHAPTER 28 Understanding Validation Controls | 525 |
| Comparing Server and Client Validations | 525 |
| Server Validation | 526 |
| Client Validation | 526 |
| Implementing Client Validation | 527 |
| CHAPTER 29 Accessing Data with Web Forms | 535 |
| Using the Web Forms DataGrid Control | 535 |
| Managing Security | 536 |
| Understanding Forms-Based Security | 536 |
| Implementing Forms-Based Security | 537 |
| Querying Data | 541 |
| Displaying Customer Information | 542 |
| Retrieving Data on Demand | 546 |
| Optimizing Data Access | 548 |
| Editing Data | 550 |
| Deleting Rows | 550 |
| Updating Rows | 553 |
| CHAPTER 30 Building ASP.NET Applications | 559 |
| Additional Features of the DataGrid Control | 559 |
| Sorting a DataGrid | 560 |
| Using Column Templates | 563 |
| Navigating Between Forms | 568 |
| Using Buttons and Hyperlinks | 569 |
| CHAPTER 31 Building an XML Web Service | 579 |
| What Is an XML Web Service? | 579 |
| The Role of SOAP | 581 |
| What Is the Web Services Description Language? | 582 |
| Building the ProductService Web Service | 584 |
| Creating the ProductService Web Service | 584 |
| Handling Complex Data | 589 |
| CHAPTER 32 Consuming a Web Service | 597 |
| Web Services, Clients, and Proxies | 597 |
| Talking SOAP: The Difficult Way | 598 |
| Talking SOAP: The Easy Way | 598 |
| Consuming the ProductService Web Service | 599 |
| Executing a Web Method Asynchronously | 606 |