INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the .NET Framework? 4 What''s in the .NET Framework? 4 Writing Applications Using the .NET Framework 5 What Is C#? 8 Applications You Can Write with C# 9 C# in this Book 10 Visual Studio 2015 10 Visual Studio Express 2015 Products 10 Solutions 11 CHAPTER 2: WRITING A C# PROGRAM 13 The Visual Studio 2015 Development Environment 14 Console Applications 17 The Solution Explorer 20 The Properties Window 21 The Error List Window 22 Desktop Applications 22 CHAPTER 3: VARIABLES AND EXPRESSIONS 29 Basic C# Syntax 30 Basic C# Console Application Structure 33 Variables 34 Simple Types 34 Variable Naming 39 Literal Values 39 Expressions 42 Mathematical Operators 42 Assignment Operators 47 Operator Precedence 48 Namespaces 49 CHAPTER 4: FLOW CONTROL 53 Boolean Logic 54 Boolean Bitwise and Assignment Operators 56 Operator Precedence Updated 58 Branching 59 The Ternary Operator 59 The if Statement 59 The switch Statement 63 Looping 66 do Loops 66 while Loops 69 for Loops 71 Interrupting Loops 72 Infinite Loops 73 CHAPTER 5: MORE ABOUT VARIABLES 77 Type Conversion 78 Implicit Conversions 78 Explicit Conversions 80 Explicit Conversions Using the Convert Commands 83 Complex Variable Types 85 Enumerations 85 Structs 89 Arrays 92 String Manipulation 99 CHAPTER 6: FUNCTIONS 107 Defining and Using Functions 108 Return Values 110 Parameters 112 Variable Scope 119 Variable Scope in Other Structures 122 Parameters and Return Values versus Global Data 123 The Main() Function 125 Struct Functions 127 Overloading Functions 128 Using Delegates 130 CHAPTER 7: DEBUGGING AND ERROR HANDLING 135 Debugging in Visual Studio 136 Debugging in Nonbreak (Normal) Mode 136 Debugging in Break Mode 144 Error Handling 153 try.catch.finally 153 Listing and Configuring Exceptions 160 CHAPTER 8: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING 163 What Is Object-Oriented Programming? 164 What Is an Object? 165 Everything''s an Object 168 The Life Cycle of an Object 168 Static and Instance Class Members 169 OOP Techniques 170 Interfaces 171 Inheritance 172 Polymorphism 175 Relationships between Objects 177 Operator Overloading 179 Events 180 Reference Types versus Value Types 180 OOP in Desktop Applications 180 CHAPTER 9: DEFINING CLASSES 187 Class Definitions in C# 188 Interface Definitions 190 System.Object 193 Constructors and Destructors 195 Constructor Execution Sequence 196 OOP Tools in Visual Studio 200 The Class View Window 200 The Object Browser 202 Adding Classes 203 Class Diagrams 204 Class Library Projects 206 Interfaces versus Abstract Classes 209 Struct Types 212 Shallow Copying versus Deep Copying 214 CHAPTER 10: DEFINING CLASS MEMBERS 217 Member Definitions 218 Defining Fields 218 Defining Methods 219 Defining Properties 220 Refactoring Members 225 Automatic Properties 226 Additional Class Member Topics 227 Hiding Base Class Methods 227 Calling Overridden or Hidden Base Class Methods 229 Using Nested Type Defi nitions 230 Interface Implementation 232 Implementing Interfaces in Classes 233 Partial Class Definitions 235 Partial Method Definitions 237 Example Application 238 Planning the Application 238 Writing the Class Library 239 A Client Application for the Class Library 246 The Call Hierarchy Window 248 CHAPTER 11: COLLECTIONS, COMPARISONS, AND CONVERSIONS 251 Collections 252 Using Collections 253 Defining Collections 258 Indexers 259 Adding a Cards Collection to CardLib 262 Keyed Collections and IDictionary 264 Iterators 266 Iterators and Collections 270 Deep Copying 271 Adding Deep Copying to CardLib 273 Comparisons 275 Type Comparisons 275 Value Comparisons 279 Conversions 295 Overloading Conversion Operators 295 The as Operator 297 CHAPTER 12: GENERICS 301 What Are Generics? 302 Using Generics 303 Nullable Types 303 The System.Collections.
Generic Namespace 311 Defining Generic Types 321 Defining Generic Classes 322 Defining Generic Interfaces 332 Defining Generic Methods 333 Defining Generic Delegates 334 Variance 335 Covariance 336 Contravariance 336 CHAPTER 13: ADDITIONAL C# TECHNIQUES 341 The : : Operator and the Global Namespace Qualifi er 342 Custom Exceptions 343 Adding Custom Exceptions to CardLib 343 Events 345 What Is an Event? 345 Handling Events 347 Defining Events 350 Expanding and Using CardLib 357 Attributes 365 Reading Attributes 366 Creating Attributes 367 Initializers 368 Object Initializers 368 Collection Initializers 371 Type Inference 374 Anonymous Types 376 Dynamic Lookup 380 The dynamic Type 381 Advanced Method Parameters 384 Optional Parameters 385 Named Parameters 386 Lambda Expressions 391 Anonymous Methods Recap 391 Lambda Expressions for Anonymous Methods 392 Lambda Expression Parameters 396 Lambda Expression Statement Bodies 396 Lambda Expressions as Delegates and Expression Trees 398 Lambda Expressions and Collections 399 PART II: WINDOWS PROGRAMMING CHAPTER 14: BASIC DESKTOP PROGRAMMING 407 XAML 408 Separation of Concerns 409 XAML in Action 409 The Playground 411 WPF Controls 412 Properties 413 Events 417 Control Layout 422 Stack Order 423 Alignment, Margins, Padding, and Dimensions 423 Border 424 Canvas 424 DockPanel 426 StackPanel 428 WrapPanel 429 Grid 430 The Game Client 433 The About Window 433 The Options Window 439 Data Binding 448 Starting a Game with the ListBox Control 453 CHAPTER 15: ADVANCED DESKTOP PROGRAMMING 461 The Main Window 462 The Menu Control 462 Routed Commands with Menus 462 Creating and Styling Controls 466 Styles 467 Templates 467 Value Converters 472 Triggers 473 Animations 475 WPF User Controls 478 Implementing Dependency Properties 478 Putting It All Together 489 Refactoring the Domain Model 489 The View Models 494 Completing the Game 502 PART III: CLOUD PROGRAMMING CHAPTER 16: BASIC CLOUD PROGRAMMING 515 The Cloud, Cloud Computing, and the Cloud Optimized Stack 516 Cloud Patterns and Best Practices 519 Using Microsoft Azure C# Libraries to Create a Storage Container 520 Creating an ASP.NET 4.6 Web Site That Uses the Storage Container 530 CHAPTER 17: ADVANCED CLOUD PROGRAMING AND DEPLOYMENT 539 Creating an ASP.NET Web API 540 Deploying and Consuming an ASP.NET Web API on Microsoft Azure 544 Scaling an ASP.NET Web API on Microsoft Azure 551 PART IV: DATA ACCESS CHAPTER 18: FILES 561 File Classes for Input and Output 562 The File and Directory Classes 563 The FileInfo Class 564 The DirectoryInfo Class 566 Path Names and Relative Paths 566 Streams 567 Classes for Using Streams 567 The FileStream Object 568 The StreamWriter Object 575 The StreamReader Object 577 Asynchronous File Access 580 Reading and Writing Compressed Files 580 Monitoring the File System 584 CHAPTER 19: XML AND JSON 593 XML Basics 594 JSON Basics 594 XML Schemas 595 XML Document Object Model 597 The XmlDocument Class 598 The XmlElement Class 598 Changing the Values of Nodes 603 Converting XML to JSON 609 Searching XML with XPath 611 CHAPTER 20: LINQ 617 LINQ to XML 618 LINQ to XML Functional Constructors 618 Working with XML Fragments 621 LINQ Providers 624 LINQ Query Syntax 624 Declaring a Variable for Results Using the var Keyword 626 Specifying the Data Source: from Clause 627 Specify Condition: where Clause 627 Selecting Items: select Clause 627 Finishing Up: Using the foreach Loop 628 Deferred Query Execution 628 LINQ Method Syntax 628 LINQ Extension Methods 629 Query Syntax versus Method Syntax 629 Lambda Expressions 630 Ordering Query Results 632 Understanding the orderby Clause 633 Querying a Large Data Set 634 Using Aggregate Operators 636 Using the Select Distinct Query 640 Ordering by Multiple Levels 642 Using Group Queries 644 Using Joins 646 CHAPTER 21: DATABASES 651 Using Databases 651 Installing SQL Server Express 652 Entity Framework 652 A Code First Database 653 But Where Is My Database? 660 Nav.