ISBN-13: 9781119795780 / Angielski / Miękka / 2021 / 864 str.
ISBN-13: 9781119795780 / Angielski / Miękka / 2021 / 864 str.
Introduction xxviiPart I: The C# LanguageChapter 1: Introducing C# 3What Is .NET? 3.NET Framework, .NET Standard, and .NET Core 4Writing Programs Using .NET 5CIL and JIT 5Assemblies 6Managed Code 7Garbage Collection 7Fitting It Together 7Linking 8What Is C#? 8Applications You Can Write with C# 9C# in This Book 10Visual Studio 10Visual Studio Products 10Solutions 11Chapter 2: Writing a C# Program 13The Visual Studio Development Environment 14Console Applications 18The Solution Explorer 21The Properties Window 22The Error List Window 23Desktop Applications 23Chapter 3: Variables and Expressions 29Basic C# Syntax 30Basic C# Console Application Structure 33Variables 34Simple Types 34Variable Naming 39Literal Values 39Binary Literals and Digit Separators 40String Literals 41Expressions 42Mathematical Operators 43Assignment Operators 48Operator Precedence 49Namespaces 50Chapter 4: Flow Control 55Boolean Logic 56Boolean Bitwise and Assignment Operators 58Operator Precedence Updated 60Branching 60The Ternary Operator 61The if Statement 61Checking More Conditions Using if Statements 64The switch Statement 65Looping 68do Loops 68while Loops 71for Loops 73Interrupting Loops 74Infinite Loops 75Chapter 5: More About Variables 79Type Conversion 80Implicit Conversions 80Explicit Conversions 82Explicit Conversions Using the Convert Commands 84Complex Variable Types 87Enumerations 87Defining Enumerations 88Structs 91Defining Structs 92Arrays 94Declaring Arrays 95foreach Loops 98Pattern Matching with switch case Expression 98Multidimensional Arrays 102Arrays of Arrays 104String Manipulation 105Chapter 6: Functions 113Defining and Using Functions 114Return Values 117Parameters 118Parameter Matching 121Parameter Arrays 121Reference and Value Parameters 123Out Parameters 125Tuples 126Variable Scope 128Variable Scope in Other Structures 131Parameters and Return Values versus Global Data 132Local Functions 134The Main() Function 135Struct Functions 137Overloading Functions 138Using Delegates 140Chapter 7: Debugging And Error Handling 145Debugging in Visual Studio 146Debugging in Nonbreak (Normal) Mode 147Outputting Debugging Information 148Tracepoints 152Diagnostics Output versus Tracepoints 154Debugging in Break Mode 155Entering Break Mode 155Monitoring Variable Content 158Stepping through Code 161Immediate and Command Windows 162The Call Stack Window 163Error Handling 163try. . .catch. . .finally 164Throw Expressions 172Listing and Configuring Exceptions 172Chapter 8: Introduction To Object-Oriented Programming 175What Is Object-Oriented Programming? 176What Is an Object? 177Properties and Fields 178Methods 179Everything's an Object 180The Life Cycle of an Object 180Constructors 180Destructors 181Static and Instance Class Members 181Static Constructors 181Static Classes 182OOP Techniques 182Interfaces 182Disposable Objects 184Inheritance 184Polymorphism 187Interface Polymorphism 188Relationships between Objects 189Containment 189Collections 190Operator Overloading 191Events 191Reference Types versus Value Types 192OOP in Desktop Applications 192Chapter 9: Defining Classes 199Class Definitions in C# 200Interface Definitions 202System.Object 205Constructors and Destructors 207Constructor Execution Sequence 209OOP Tools in Visual Studio 212The Class View Window 212The Object Browser 214Adding Classes 216Class Diagrams 217Class Library Projects 219Interfaces versus Abstract Classes 223Struct Types 225Shallow Copying versus Deep Copying 227Chapter 10: Defining Class Members 231Member Definitions 232Defining Fields 232Defining Methods 233Defining Properties 234Tuple Deconstruction 239Refactoring Members 240Automatic Properties 241Additional Class Member Topics 242Hiding Base Class Methods 242Calling Overridden or Hidden Base Class Methods 244The this Keyword 244Using Nested Type Definitions 245Interface Implementation 247Implementing Interfaces in Classes 248Explicit Interface Member Implementation 249Additional Property Accessors 249Partial Class Definitions 250Partial Method Definitions 251Example Application 252Planning the Application 253The Card Class 253The Deck Class 253Writing the Class Library 253Adding the Suit and Rank Enumerations 254Adding the Card Class 256Adding the Deck Class 258A Client Application for the Class Library 261The Call Hierarchy Window 262Chapter 11: Collections, Comparisons, and Conversions 265Collections 266Using Collections 267Defining Collections 272Indexers 273Adding a CardCollection to CardLib 275Keyed Collections and IDictionary 278Iterators 279Iterators and Collections 284Deep Copying 285Adding Deep Copying to CardLib 286Comparisons 288Type Comparisons 288Boxing and Unboxing 289The is Operator 290Pattern Matching with the is Operator Pattern Expression 293Value Comparisons 294Operator Overloading 294Adding Operator Overloads to CardLib 299The IComparable and IComparer Interfaces 304Sorting Collections 306Conversions 309Overloading Conversion Operators 310The as Operator 311Chapter 12: Generics 315What Are Generics? 316Using Generics 317Nullable Types 317Operators and Nullable Types 318The ?? Operator 319The ?. Operator 320Working with Nullable Types 321The System.Collections.Generic Namespace 325List 326Sorting and Searching Generic Lists 327Dictionary 333Modifying CardLib to Use a Generic Collection Class 334Defining Generic Types 335Defining Generic Classes 336The default Keyword 338Constraining Types 338Inheriting from Generic Classes 344Generic Operators 345Generic Structs 346Defining Generic Interfaces 346Defining Generic Methods 346Defining Generic Delegates 348Variance 348Covariance 349Contravariance 350Chapter 13: Additional C# Techniques 355The :: Operator and the Global Namespace Qualifier 356Custom Exceptions 357Adding Custom Exceptions to CardLib 358Events 359What Is an Event? 359Handling Events 361Defining Events 363Multipurpose Event Handlers 367The EventHandler and Generic EventHandler Types 370Return Values and Event Handlers 370Anonymous Methods 370Expanding and Using CardLib 371Attributes 380Reading Attributes 380Creating Attributes 381Initializers 382Object Initializers 383Collection Initializers 385Type Inference 388Anonymous Types 390Dynamic Lookup 394The dynamic Type 395Advanced Method Parameters 399Optional Parameters 399Optional Parameter Values 400The OptionalAttribute Attribute 400Optional Parameter Order 401Named Parameters 401Lambda Expressions 405Anonymous Methods Recap 405Lambda Expressions for Anonymous Methods 407Lambda Expression Parameters 410Lambda Expression Statement Bodies 411Lambda Expressions as Delegates and Expression Trees 412Lambda Expressions and Collections 413Part II: Data AccessChapter 14: Files 423File Classes for Input and Output 424The File and Directory Classes 424The FileInfo Class 426The DirectoryInfo Class 428Path Names and Relative Paths 428Streams 429Classes for Using Streams 429The FileStream Object 429File Position 430Reading Data 432Writing Data 434The StreamWriter Object 436The StreamReader Object 439Reading Data 440Asynchronous File Access 441Reading and Writing Compressed Files 442Monitoring the File System 445Chapter 15: XML and JSON 453XML Basics 454JSON Basics 455XML Schemas 455XML Document Object Model 458The XmlDocument Class 458The XmlElement Class 459Changing the Values of Nodes 463Inserting New Nodes 465Deleting Nodes 467Selecting Nodes 469Searching XML with XPath 469JSON Serialization and Deserialization 473Chapter 16: LINQ 479LINQ to XML 480LINQ to XML Functional Constructors 480Working with XML Fragments 483LINQ Providers 486LINQ Query Syntax 486Declaring a Variable for Results Using the var Keyword 488Specifying the Data Source: from Clause 489Specify Condition: where Clause 489Selecting Items: select Clause 490Finishing Up: Using the foreach Loop 490Deferred Query Execution 490LINQ Method Syntax 490LINQ Extension Methods 491Query Syntax versus Method Syntax 491Lambda Expressions 492Ordering Query Results 494Understanding the orderby Clause 495Querying a Large Data Set 496Using Aggregate Operators 498Using the Select Distinct Query 502Ordering by Multiple Levels 504Using Group Queries 506Using Joins 508Chapter 17: Databases 513Using Databases 514Entity Framework 514Code-First versus Database-First 514Migrations and Scaffolding 515Install SQL Server Express LocalDB 515A Code-First Database 516Exploring Your Database 527Navigating Database Relationships 530Creating and Querying XML from an Existing Database 536Part III: Additional TechniquesChapter 18: .NET and ASP.NET 545Cross-Platform Basics and Key "Must Know" Terms 547What was .NET Standard? 549Shared Project, PCL, and .NET Standard 551Building and Packaging a .NET Standard Library 553Referencing and Targeting .NET 557What was .NET Core? 558Cross Platform 558Open Source 559Optimized for the Cloud 560Performance 560Modular Design 561Self-ContainedDeployment Model 562Porting from .NET Framework to .NET 565Identifying Third-Party Dependencies 567Understanding Which Features Are Not Available 567Upgrading the Current .NET Framework Target 567Overview of Web Applications 568Which ASP.NET to Use and Why 569ASP.NET Web Forms 570Server Controls 572Input Validation 573State Management 574Authentication and Authorization 575ASP.NET Web Site versus ASP.NET Web Applications 575ASP.NET MVC/ASP.NET Core Web App MVC 577ASP.NET Core Web API 579ASP.NET Core Web App 580IIS and Kestrel 581Blazor App and Razor Pages 582Input Validation 584State Management 585Authentication and Authorization 586Dependency Injection 586Chapter 19: Basic Cloud Programming 591The Cloud, Cloud Computing, and the Cloud Optimized Stack 592Cloud Patterns and Best Practices 595Using Microsoft Azure C# Libraries to Create a Storage Container 597Creating an ASP.NET Core Web Application That Uses the Storage Container 607Chapter 20: Basic Web API AND WCF Programming 617Creating an ASP.NET Core Web API 617Consuming an ASP.NET Core Web API 622What Is REST? 629What Is WCF? 630WCF Concepts 631WCF Communication Protocols 631Addresses, Endpoints, and Bindings 632Contracts 634Message Patterns 634Behaviors 635Hosting 635WCF Programming 635The WCF Test Client 642Defining WCF Service Contracts 644Data Contracts 645Service Contracts 645Operation Contracts 646Message Contracts 647Fault Contracts 647Self-HostedWCF Services 652Chapter 21: Basic Desktop Programming 663XAML 664Separation of Concerns 665XAML in Action 665Namespaces 666Code-BehindFiles 667The Playground 667WPF Controls 669Properties 670Dependency Properties 673Attached Properties 673Events 674Handling Events 675Routed Events 676Routed Commands 676Control Types 679Control Layout 679Basic Layout Concepts 679Stack Order 679Alignment, Margins, Padding, and Dimensions 680Border 680Visual Debugging Tools 681Layout Panels 682Canvas 682DockPanel 684StackPanel 686WrapPanel 687Grid 688The Game Client 691The About Window 691Designing the User Interface 692The Image Control 692The Label Control 692The TextBlock Control 693The Button Control 693The Options Window 696The TextBox Control 697The CheckBox Control 698The RadioButton Control 699The ComboBox Control 700The TabControl 701Handling Events in the Options Window 705Data Binding 707The DataContext 708Binding to Local Objects 708Static Binding to External Objects 709Dynamic Binding to External Objects 710Starting a Game with the ListBox Control 712Creating and Styling Controls 716Styles 716Templates 717Triggers 719Animations 720WPF User Controls 721Implementing Dependency Properties 722The Main Window 736The Menu Control 736Routed Commands with Menus 736Putting It All Together 741Refactoring the Domain Model 741The View Model 748Completing the Game 757Appendix: Exercise Solutions 769Index 809
About the authorsBenjamin Perkins is a Sr. Escalation Engineer at Microsoft. His experience includes designing, developing, deploying, administering, and managing enterprise-level IT solutions.Jon D. Reid is a Program Manager in Research and Development at IFS AB, specializing in Field Service Management using C# and .NET.
1997-2024 DolnySlask.com Agencja Internetowa