Beginning Visual C# 2012 Programming
Häftad, Engelska, 2012
Av Karli Watson, Jacob Vibe Hammer, Jon D. Reid, Morgan Skinner, Daniel Kemper, Christian Nagel, Jon D Reid
539 kr
Produktinformation
- Utgivningsdatum2012-12-18
- Mått185 x 234 x 48 mm
- Vikt1 520 g
- FormatHäftad
- SpråkEngelska
- Antal sidor912
- FörlagJohn Wiley & Sons Inc
- ISBN9781118314418
Tillhör följande kategorier
Karli Watson is an author and IT contractor in London. Jacob Vibe Hammer is a software architect and developer at Kamstrup A/S, Denmark. He has coauthored several books. Jon D. Reid is the director of systems engineering at Indigo Biosystems, Inc. Morgan Skinner joined Microsoft in 2001. Daniel Kemper is a software engineer specializing in reporting and rich client technologies. Christian Nagel is a Microsoft Regional Director and Microsoft MVP, an associate of thinktecture, and founder of CN innovation. Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved.
- INTRODUCTION xxxiPART I: THE C# LANGUAGECHAPTER 1: INTRODUCING C# 3What Is the .NET Framework? 3What’s in the .NET Framework? 4Writing Applications Using the .NET Framework 4CIL and JIT 4Assemblies 5Managed Code 5Garbage Collection 6Fitting It Together 6Linking 7What Is C#? 7Applications You Can Write with C# 8C# in this Book 8Visual Studio 2012 8Visual Studio Express 2012 Products 9Solutions 9Summary 10CHAPTER 2: WRITING A C# PROGRAM 13The Visual Studio 2012 Development Environment 14Console Applications 16The Solution Explorer 18The Properties Window 19The Error List Window 19Desktop Applications 20Summary 23CHAPTER 3: VARIABLES AND EXPRESSIONS 25Basic C# Syntax 26Basic C# Console Application Structure 28Variables 29Simple Types 29Variable Naming 33Naming Conventions 34Literal Values 34Variable Declaration and Assignment 36Expressions 37Mathematical Operators 37Assignment Operators 41Operator Precedence 42Namespaces 42Summary 45CHAPTER 4: FLOW CONTROL 49Boolean Logic 49Boolean Assignment Operators 52Bitwise Operators 53Operator Precedence Updated 57The goto Statement 58Branching 59The Ternary Operator 59The if Statement 59Checking More Conditions Using if Statements 62The switch Statement 63Looping 65do Loops 66while Loops 68for Loops 70Interrupting Loops 74Infi nite Loops 75Summary 75CHAPTER 5: MORE ABOUT VARIABLES 79Type Conversion 80Implicit Conversions 80Explicit Conversions 81Explicit Conversions Using the Convert Commands 84Complex Variable Types 86Enumerations 87Defi ning Enumerations 87Structs 90Defi ning Structs 90Arrays 92Declaring Arrays 93foreach Loops 95Multidimensional Arrays 96Arrays of Arrays 97String Manipulation 98Summary 102CHAPTER 6: FUNCTIONS 105Defi ning and Using Functions 106Return Values 108Parameters 109Parameter Matching 111Parameter Arrays 111Reference and Value Parameters 113Out Parameters 115Variable Scope 116Variable Scope in Other Structures 118Parameters and Return Values versus Global Data 120The Main( ) Function 121Struct Functions 123Overloading Functions 124Using Delegates 125Summary 128CHAPTER 7: DEBUGGING AND ERROR HANDLING 131Debugging in Visual Studio 132Debugging in Nonbreak (Normal) Mode 132Outputting Debugging Information 133Tracepoints 137Diagnostics Output Versus Tracepoints 139Debugging in Break Mode 140Entering Break Mode 140Monitoring Variable Content 142Stepping Through Code 144Immediate and Command Windows 146The Call Stack Window 146Error Handling 147try…catch…finally 147Listing and Configuring Exceptions 152Notes on Exception Handling 152Summary 153CHAPTER 8: INTRODUCTION TO OBJECT-ORIENTEDPROGRAMMING 157What Is Object-Oriented Programming? 158What Is an Object? 158Properties and Fields 159Methods 160Everything’s an Object 161The Life Cycle of an Object 161Constructors 161Destructors 162Static and Instance Class Members 162Static Constructors 162Static Classes 163OOP Techniques 163Interfaces 163Disposable Objects 164Inheritance 165Polymorphism 167Interface Polymorphism 168Relationships Between Objects 168Containment 168Collections 169Operator Overloading 169Events 170Reference Types Versus Value Types 170OOP in Desktop Applications 171Summary 174CHAPTER 9: DEFINING CLASSES 177Class Defi nitions in C# 177Interface Defi nitions 180System.Object 182Constructors and Destructors 184Constructor Execution Sequence 185OOP Tools in Visual Studio 188The Class View Window 188The Object Browser 190Adding Classes 191Class Diagrams 192Class Library Projects 193Interfaces Versus Abstract Classes 196Struct Types 198Shallow Copying Versus Deep Copying 200Summary 200CHAPTER 10: DEFINING CLASS MEMBERS 203Member Defi nitions 203Defi ning Fields 204Defi ning Methods 204Defi ning Properties 205Adding Members from a Class Diagram 210Adding Methods 210Adding Properties 212Adding Fields 212Refactoring Members 212Automatic Properties 213Additional Class Member Topics 213Hiding Base Class Methods 213Calling Overridden or Hidden Base Class Methods 215The this Keyword 216Using Nested Type Defi nitions 216Interface Implementation 218Implementing Interfaces in Classes 219Explicit Interface Member Implementation 220Additional Property Accessors 220Partial Class Defi nitions 221Partial Method Defi nitions 222Example Application 224Planning the Application 224The Card Class 224The Deck Class 224Writing the Class Library 224Adding the Suit and Rank Enumerations 225Adding the Card Class 226Adding the Deck Class 227A Client Application for the Class Library 230The Call Hierarchy Window 231Summary 232CHAPTER 11: COLLECTIONS, COMPARISONS, AND CONVERSIONS 235Collections 236Using Collections 236Defi ning Collections 241Indexers 242Adding a Cards Collection to CardLib 244Keyed Collections and IDictionary 247Iterators 248Iterators and Collections 252Deep Copying 253Adding Deep Copying to CardLib 255Comparisons 256Type Comparisons 256Boxing and Unboxing 257The is Operator 258Value Comparisons 260Operator Overloading 261Adding Operator Overloads to CardLib 265The IComparable and IComparer Interfaces 269Sorting Collections 271Conversions 274Overloading Conversion Operators 274The as Operator 275Summary 276CHAPTER 12: GENERICS 279What Are Generics? 280Using Generics 281Nullable Types 281Operators and Nullable Types 282The ?? Operator 283The System.Collections.Generic Namespace 287List 287Sorting and Searching Generic Lists 289Dictionary 294Modifying CardLib to Use a Generic Collection Class 295Defi ning Generic Types 296Defi ning Generic Classes 296The default Keyword 298Constraining Types 298Inheriting from Generic Classes 304Generic Operators 305Generic Structs 306Defi ning Generic Interfaces 306Defi ning Generic Methods 306Defi ning Generic Delegates 308Variance 308Covariance 309Contravariance 310Summary 310CHAPTER 13: ADDITIONAL OOP TECHNIQUES 313The :: Operator and the Global Namespace Qualifi er 313Custom Exceptions 315Adding Custom Exceptions to CardLib 315Events 316What Is an Event? 316Handling Events 317Defi ning Events 319Multipurpose Event Handlers 323The EventHandler and Generic EventHandler Types 325Return Values and Event Handlers 326Anonymous Methods 326Expanding and Using CardLib 327A Card Game Client for CardLib 327Attributes 334Reading Attributes 334Creating Attributes 335Summary 336CHAPTER 14: C# LANGUAGE ENHANCEMENTS 339Initializers 340Object Initializers 340Collection Initializers 342Type Inference 344Anonymous Types 346Dynamic Lookup 350The dynamic Type 350IDynamicMetaObjectProvider 354Advanced Method Parameters 354Optional Parameters 354Optional Parameter Values 355The OptionalAttribute Attribute 356Optional Parameter Order 356Named Parameters 356Named and Optional Parameter Guidelines 360Extension Methods 360Lambda Expressions 364Anonymous Methods Recap 364Lambda Expressions for Anonymous Methods 365Lambda Expression Parameters 368Lambda Expression Statement Bodies 368Lambda Expressions as Delegates and Expression Trees 369Lambda Expressions and Collections 370Caller Information Attributes 372Summary 375PART II: WINDOWS PROGRAMMINGCHAPTER 15: BASIC DESKTOP PROGRAMMING 381XAML 382Separation of Concerns 382XAML in Action 383Namespaces 383Code-Behind Files 384The Playground 384WPF Controls 385Properties 386Dependency Properties 387Attached Properties 388Events 388Handling Events 389Routed Events 390Routed Commands 390Control Types 392Control Layout 393Stack Order 393Alignment, Margins, Padding, and Dimensions 393Border 394Canvas 394DockPanel 395StackPanel 397WrapPanel 398Grid 398The Game Client 401The About Window 401Designing the User Interface 401The Image Control 401The Label Control 402The TextBlock Control 402The Button Control 402The Options Window 405The TextBox Control 406The CheckBox Control 406The RadioButton Control 407The ComboBox Control 408The TabControl 409Handling Events in the Options Window 411Data Binding 413The DataContext 414Binding to Local Objects 414Static Binding to External Objects 414Dynamic Binding to External Objects 415Starting a Game 418The ListBox Control 418Summary 421CHAPTER 16: ADVANCED DESKTOP PROGRAMMING 425The Main Window 425The Menu Control 426Routed Commands with Menus 426Creating and Styling Controls 429Styles 430Templates 430Value Converters 434The IValueConverter Interface 434ValueConversionAttribute 434Triggers 435Animations 436Timelines without Key Frames 436Timelines with Key Frames 437WPF User Controls 438Implementing Dependency Properties 439Putting It All Together 447Refactoring the Domain Model 447The View Models 451Completing the Game 459Summary 466CHAPTER 17: WINDOWS STORE APPS 469Getting Started 469Windows 8 Developer License 470How to Get the License 470Windows Store Apps versus Desktop Applications 471Developing Windows Store Apps 472View Modes 472Full-Screen Mode 473Snapped Mode 473Fill Mode 473Screen Orientation 473The Missing Caption Bar 473Menus and Toolbars 473The App Bar 474Charms 475Tiles and Badges 476App Lifetime 476Lock Screen Apps 476App Development 476WPF and Windows Store App XAML Diff erences 476Namespace Changes 477Eff ects 477Opacity Mask 477Style Triggers 477Commands 478Templates and Pages 478Blank Page 478Basic Page 478Grouped Items and Group Details Pages 478Item Details Page 479Items and Split Pages 479Sandboxed Apps 479Disk Access 479Serialization, Streams, and Async Programming 480Navigation Between Pages 483Managing State 485Converting KarliCards, Part 1 485Creating the CardLib Project 486Converting the View Models 489Visual Changes 493Drop Shadow and Opacity Masks 493Style Triggers 493Converting User Controls 493Common Elements of Windows Store Apps 499The AppBar Control 500The Settings Panel 501Tiles, Badges, and Splash Screens 503Converting KarliCards, Part 2 504The Windows Store 509Checking the Store Requirements 509Summary 510CHAPTER 18: DEPLOYING DESKTOP APPLICATIONS 513Deployment Overview 514ClickOnce Deployment 514Implementing ClickOnce Deployment 515Installing the Application with ClickOnce 522Creating and Using Updates of the Application 524InstallShield Limited Edition 524The Project Assistant 524Step 1: Application Information 525Step 2: Installation Requirements 525Step 3: Installation Architecture 526Step 4: Application Files 526Step 5: Application Shortcuts 527Step 6: Application Registry 528Step 7: Installation Interview 528Summary 530PART III: WEB PROGRAMMINGCHAPTER 19: ASP.NET WEB PROGRAMMING 535Overview of Web Applications 536ASP.NET Runtime 536Creating a Simple Page 536Server Controls 544ASP.NET Postback 545ASP.NET AJAX Postback 550Input Validation 553State Management 557Client-Side State Management 558View State 558Cookie 559Server-Side State Management 560Session 560Application 561Cache 562Styles 562Master Pages 566Site Navigation 571Authentication and Authorization 573Authentication Confi guration 574Using Security Controls 577Reading from and Writing to a SQL Server Database 580Summary 589CHAPTER 20: DEPLOYING WEB APPLICATIONS 591Internet Information Services 591IIS Confi guration 592Copying a Website 594Publishing a Web Application 597Summary 600PART IV: DATA ACCESSCHAPTER 21: FILE SYSTEM DATA 605Streams 605The Classes for Input and Output 606The File and Directory Classes 607The FileInfo Class 608The DirectoryInfo Class 610Path Names and Relative Paths 611The FileStream Object 611File Position 612Reading Data 613Writing Data 615The StreamWriter Object 617The StreamReader Object 618Reading Data 620Delimited Files 621Asynchronous File Access 625Reading and Writing Compressed Files 625Serialized Objects 628Monitoring the File System 632Summary 636CHAPTER 22: XML 639XML Documents 640XML Elements 640Attributes 641The XML Declaration 641The Structure of an XML Document 642XML Namespaces 642Well-Formed and Valid XML 643Validating XML Documents 644Schemas 644The XSD dialog box shown in the XmlDocument Class 645Using XML in Your Application 647XML Document Object Model 647The XmlDocument Class 648The XmlElement Class 648Changing the Values of Nodes 652Selecting Nodes 656XPath 657Summary 661CHAPTER 23: INTRODUCTION TO LINQ 663First LINQ Query 664Declaring a Variable for Results Using the var Keyword 665Specifying the Data Source: from Clause 666Specify Condition: where Clause 666Selecting Items: select Clause 666Finishing Up: Using the foreach Loop 667Deferred Query Execution 667Using the LINQ Method Syntax 667LINQ Extension Methods 667Query Syntax versus Method Syntax 668Ordering Query Results 669Understanding the orderby Clause 670Ordering Using Method Syntax 671Querying a Large Data Set 672Using Aggregate Operators 674Querying Complex Objects 678Projection: Creating New Objects in Queries 681Projection: Method Syntax 682Using the Select Distinct Query 683Using the Any and All Methods 684Ordering by Multiple Levels 685Multi-Level Ordering Method Syntax: ThenBy 687Using Group Queries 687Using Take and Skip 689Using First and FirstOrDefault 691Using the LINQ Set Operators 692Using Joins 694Summary 696CHAPTER 24: APPLYING LINQ 699LINQ Varieties 699Using LINQ with Databases 700Installing SQL Server and the Northwind Sample Data 700Installing SQL Server Express 701Installing the Northwind Sample Database 701First LINQ to Database Query 701Navigating Database Relationships 704Using LINQ with XML 706LINQ to XML Functional Constructors 707Constructing XML Element Text with Strings 710Saving and Loading an XML Document 710Loading XML from a String 712Contents of a Saved XML Document 713Working with XML Fragments 713Generating XML from Databases 715How to Query an XML Document 717Using LINQ to XML Query Members 718Elements( ) 718Descendants( ) 719Attributes( ) 721Summary 723PART V: ADDITIONAL TECHNIQUESCHAPTER 25: WINDOWS COMMUNICATION FOUNDATION 727What Is WCF? 728WCF Concepts 728WCF Communication Protocols 729Addresses, Endpoints, and Bindings 729Contracts 731Message Patterns 732Behaviors 732Hosting 732WCF Programming 733The WCF Test Client 740Defi ning WCF Service Contracts 742Data Contracts 743Service Contracts 743Operation Contracts 744Message Contracts 745Fault Contracts 745Self-Hosted WCF Services 750Summary 756CHAPTER 26: WINDOWS WORKFLOW FOUNDATION 759Hello World 759Workfl ows and Activities 761If Activity 761While Activity 762Sequence Activity 762Arguments and Variables 763Custom Activities 767Workfl ow Extensions 769Activity Validation 773Activity Designers 774Summary 776APPENDIX A: EXERCISE SOLUTIONS 779INDEX 827