Pro c 7 with net and net core ( pdfdrive com )

1.4K 1 0
Pro c 7  with  net and  net core ( pdfdrive com )

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Pro C# With NET and NET Core — Eighth Edition — Andrew Troelsen Philip Japikse Pro C# With NET and NET Core Eighth Edition Andrew Troelsen Philip Japikse Pro C# 7: With NET and NET Core Andrew Troelsen Philip Japikse Minneapolis, Minnesota, USA West Chester, Ohio, USA ISBN-13 (pbk): 978-1-4842-3017-6 https://doi.org/10.1007/978-1-4842-3018-3 ISBN-13 (electronic): 978-1-4842-3018-3 Library of Congress Control Number: 2017958717 Copyright © 2017 by Andrew Troelsen and Philip Japikse This work is subject to copyright All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed Trademarked names, logos, and images may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made The publisher makes no warranty, express or implied, with respect to the material contained herein Cover image by Freepik (www.freepik.com) Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Gwenan Spearing Development Editor: Laura Berendson Technical Reviewers: Eric Potter, Lee Brandt, and Sean Whitesell Coordinating Editor: Mark Powers Copy Editor: Kim Wimpsett Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc) SSBM Finance Inc is a Delaware corporation For information on translations, please e-mail rights@apress.com, or visit www.apress.com/ rights-permissions Apress titles may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484230176 For more detailed information, please visit www.apress.com/source-code Printed on acid-free paper To the entire Troelsen clan: Mary (mom), Walter (dad), Mandy (wife), and Soren (son) We miss you, Mikko (the cat) —Andrew To my family, Amy (wife), Conner (son), Logan (son), and Skylar (daughter), thank you for all of the support and patience you have given me —Philip Contents at a Glance About the Authors����������������������������������������������������������������������������������������������������� li About the Technical Reviewers������������������������������������������������������������������������������ liii Acknowledgments��������������������������������������������������������������������������������������������������� lv Introduction����������������������������������������������������������������������������������������������������������� lvii ■Part ■ I: Introducing C# and the NET Platform������������������������������������� ■Chapter ■ 1: The Philosophy of NET������������������������������������������������������������������������� ■Chapter ■ 2: Building C# Applications�������������������������������������������������������������������� 35 ■Part ■ II: Core C# Programing�������������������������������������������������������������� 53 ■Chapter ■ 3: Core C# Programming Constructs, Part I������������������������������������������� 55 ■Chapter ■ 4: Core C# Programming Constructs, Part II���������������������������������������� 111 ■Part ■ III: Object-Oriented Programming with C#������������������������������ 159 ■Chapter ■ 5: Understanding Encapsulation���������������������������������������������������������� 161 ■Chapter ■ 6: Understanding Inheritance and Polymorphism�������������������������������� 213 ■Chapter ■ 7: Understanding Structured Exception Handling�������������������������������� 255 ■Chapter ■ 8: Working with Interfaces������������������������������������������������������������������� 283 ■Part ■ IV: Advanced C# Programming����������������������������������������������� 323 ■Chapter ■ 9: Collections and Generics������������������������������������������������������������������ 325 ■Chapter ■ 10: Delegates, Events, and Lambda Expressions��������������������������������� 365 ■Chapter ■ 11: Advanced C# Language Features��������������������������������������������������� 407 ■Chapter ■ 12: LINQ to Objects������������������������������������������������������������������������������� 445 ■Chapter ■ 13: Understanding Object Lifetime������������������������������������������������������� 479 v ■ Contents at a Glance ■Part ■ V: Programming with NET Assemblies����������������������������������� 507 ■Chapter ■ 14: Building and Configuring Class Libraries��������������������������������������� 509 ■■Chapter 15: Type Reflection, Late Binding, and Attribute-Based Programming���� 561 ■Chapter ■ 16: Dynamic Types and the Dynamic Language Runtime�������������������� 609 ■Chapter ■ 17: Processes, AppDomains, and Object Contexts������������������������������� 631 ■Chapter ■ 18: Understanding CIL and the Role of Dynamic Assemblies��������������� 657 ■Part ■ VI: Introducing the NET Base Class Libraries������������������������� 699 ■Chapter ■ 19: Multithreaded, Parallel, and Async Programming������������������������� 701 ■Chapter ■ 20: File I/O and Object Serialization���������������������������������������������������� 755 ■Chapter ■ 21: Data Access with ADO.NET������������������������������������������������������������� 803 ■Chapter ■ 22: Introducing Entity Framework 6���������������������������������������������������� 857 ■Chapter ■ 23: Introducing Windows Communication Foundation������������������������ 907 ■Part ■ VII: Windows Presentation Foundation����������������������������������� 963 ■Chapter ■ 24: Introducing Windows Presentation Foundation and XAML������������� 965 ■Chapter ■ 25: WPF Controls, Layouts, Events, and Data Binding������������������������ 1003 ■Chapter ■ 26: WPF Graphics Rendering Services����������������������������������������������� 1061 ■Chapter ■ 27: WPF Resources, Animations, Styles, and Templates�������������������� 1095 ■Chapter ■ 28: WPF Notifications, Validations, Commands, and MVVM��������������� 1137 ■Part ■ VIII: ASP.NET.������������������������������������������������������������������������� 1177 ■Chapter ■ 29: Introducing ASP.NET MVC������������������������������������������������������������� 1179 ■Chapter ■ 30: Introducing ASP.NET Web API������������������������������������������������������� 1223 ■Part ■ IX: NET CORE������������������������������������������������������������������������ 1243 ■Chapter ■ 31: The Philosophy of NET Core�������������������������������������������������������� 1245 ■Chapter ■ 32: Introducing Entity Framework Core��������������������������������������������� 1255 ■Chapter ■ 33: Introducing ASP.NET Core Web Applications�������������������������������� 1279 ■Chapter ■ 34: Introducing ASP.NET Core Service Applications��������������������������� 1329 Index������������������������������������������������������������������������������������������������������������������� 1353 vi Contents About the Authors����������������������������������������������������������������������������������������������������� li About the Technical Reviewers������������������������������������������������������������������������������ liii Acknowledgments��������������������������������������������������������������������������������������������������� lv Introduction����������������������������������������������������������������������������������������������������������� lvii ■Part ■ I: Introducing C# and the NET Platform������������������������������������� ■Chapter ■ 1: The Philosophy of NET������������������������������������������������������������������������� An Initial Look at the NET Platform��������������������������������������������������������������������������������� Some Key Benefits of the NET Platform������������������������������������������������������������������������������������������������ Introducing the Building Blocks of the NET Platform (the CLR, CTS, and CLS)���������������� The Role of the Base Class Libraries������������������������������������������������������������������������������������������������������ What C# Brings to the Table������������������������������������������������������������������������������������������������������������������� Managed vs Unmanaged Code�������������������������������������������������������������������������������������������������������������� Additional NET-Aware Programming Languages������������������������������������������������������������� Life in a Multilanguage World����������������������������������������������������������������������������������������������������������������� An Overview of NET Assemblies�������������������������������������������������������������������������������������� The Role of the Common Intermediate Language�������������������������������������������������������������������������������� 10 Benefits of CIL�������������������������������������������������������������������������������������������������������������������������������������� 13 Compiling CIL to Platform-Specific Instructions����������������������������������������������������������������������������������� 13 The Role of NET Type Metadata����������������������������������������������������������������������������������������������������������� 13 The Role of the Assembly Manifest������������������������������������������������������������������������������������������������������ 14 Understanding the Common Type System���������������������������������������������������������������������� 15 CTS Class Types������������������������������������������������������������������������������������������������������������������������������������ 15 CTS Interface Types������������������������������������������������������������������������������������������������������������������������������ 16 vii ■ Contents CTS Structure Types����������������������������������������������������������������������������������������������������������������������������� 16 CTS Enumeration Types������������������������������������������������������������������������������������������������������������������������ 17 CTS Delegate Types������������������������������������������������������������������������������������������������������������������������������ 17 CTS Type Members������������������������������������������������������������������������������������������������������������������������������� 17 Intrinsic CTS Data Types����������������������������������������������������������������������������������������������������������������������� 18 Understanding the Common Language Specification���������������������������������������������������� 19 Ensuring CLS Compliance��������������������������������������������������������������������������������������������������������������������� 20 Understanding the Common Language Runtime������������������������������������������������������������ 20 The Assembly/Namespace/Type Distinction������������������������������������������������������������������ 22 The Role of the Microsoft Root Namespace����������������������������������������������������������������������������������������� 25 Accessing a Namespace Programmatically����������������������������������������������������������������������������������������� 25 Referencing External Assemblies��������������������������������������������������������������������������������������������������������� 26 Exploring an Assembly Using ildasm.exe����������������������������������������������������������������������� 27 Viewing CIL Code���������������������������������������������������������������������������������������������������������������������������������� 28 Viewing Type Metadata������������������������������������������������������������������������������������������������������������������������� 29 Viewing Assembly Metadata (aka the Manifest)����������������������������������������������������������������������������������� 30 The Platform-Independent Nature of NET��������������������������������������������������������������������� 30 The Mono Project���������������������������������������������������������������������������������������������������������������������������������� 32 Xamarin������������������������������������������������������������������������������������������������������������������������������������������������ 32 Microsoft NET Core������������������������������������������������������������������������������������������������������������������������������ 32 Summary������������������������������������������������������������������������������������������������������������������������ 33 ■Chapter ■ 2: Building C# Applications�������������������������������������������������������������������� 35 Building NET Applications on Windows������������������������������������������������������������������������� 35 Installing Visual Studio 2017���������������������������������������������������������������������������������������������������������������� 36 Taking Visual Studio 2017 for a Test-Drive������������������������������������������������������������������������������������������� 38 Visual Studio 2017 Professional����������������������������������������������������������������������������������������������������������� 50 Visual Studio 2017 Enterprise�������������������������������������������������������������������������������������������������������������� 50 The NET Framework Documentation System�������������������������������������������������������������������������������������� 50 Building.NET Applications on a Non-Windows OS���������������������������������������������������������� 52 Summary������������������������������������������������������������������������������������������������������������������������ 52 viii ■ Contents ■Part ■ II: Core C# Programing�������������������������������������������������������������� 53 ■Chapter ■ 3: Core C# Programming Constructs, Part I������������������������������������������� 55 The Anatomy of a Simple C# Program���������������������������������������������������������������������������� 55 Variations on the Main( ) Method���������������������������������������������������������������������������������������������������������� 57 Specifying an Application Error Code��������������������������������������������������������������������������������������������������� 58 Processing Command-Line Arguments������������������������������������������������������������������������������������������������ 59 Specifying Command-Line Arguments with Visual Studio�������������������������������������������������������������������� 61 An Interesting Aside: Some Additional Members of the System.Environment Class������ 61 The System.Console Class��������������������������������������������������������������������������������������������� 63 Basic Input and Output with the Console Class������������������������������������������������������������������������������������ 63 Formatting Console Output������������������������������������������������������������������������������������������������������������������� 65 Formatting Numerical Data������������������������������������������������������������������������������������������������������������������ 65 Formatting Numerical Data Beyond Console Applications������������������������������������������������������������������� 67 System Data Types and Corresponding C# Keywords���������������������������������������������������� 68 Variable Declaration and Initialization�������������������������������������������������������������������������������������������������� 69 Intrinsic Data Types and the new Operator������������������������������������������������������������������������������������������� 71 The Data Type Class Hierarchy������������������������������������������������������������������������������������������������������������� 72 Members of Numerical Data Types������������������������������������������������������������������������������������������������������� 73 Members of System.Boolean���������������������������������������������������������������������������������������������������������������� 74 Members of System.Char��������������������������������������������������������������������������������������������������������������������� 74 Parsing Values from String Data����������������������������������������������������������������������������������������������������������� 75 Using TryParse to Parse Values from String Data��������������������������������������������������������������������������������� 75 System.DateTime and System.TimeSpan��������������������������������������������������������������������������������������������� 76 The System.Numerics.dll Assembly����������������������������������������������������������������������������������������������������� 76 Digit Separators (New)������������������������������������������������������������������������������������������������������������������������� 78 Binary Literals (New)���������������������������������������������������������������������������������������������������������������������������� 78 Working with String Data����������������������������������������������������������������������������������������������� 79 Basic String Manipulation�������������������������������������������������������������������������������������������������������������������� 80 String Concatenation���������������������������������������������������������������������������������������������������������������������������� 80 Escape Characters�������������������������������������������������������������������������������������������������������������������������������� 81 ix ■ Contents Defining Verbatim Strings��������������������������������������������������������������������������������������������������������������������� 82 Strings and Equality����������������������������������������������������������������������������������������������������������������������������� 82 Strings Are Immutable�������������������������������������������������������������������������������������������������������������������������� 85 The System.Text.StringBuilder Type����������������������������������������������������������������������������������������������������� 86 String Interpolation������������������������������������������������������������������������������������������������������������������������������� 87 Narrowing and Widening Data Type Conversions����������������������������������������������������������� 88 The checked Keyword�������������������������������������������������������������������������������������������������������������������������� 91 Setting Project-wide Overflow Checking���������������������������������������������������������������������������������������������� 93 The unchecked Keyword���������������������������������������������������������������������������������������������������������������������� 93 Understanding Implicitly Typed Local Variables������������������������������������������������������������� 94 Restrictions on Implicitly Typed Variables�������������������������������������������������������������������������������������������� 95 Implicit Typed Data Is Strongly Typed Data������������������������������������������������������������������������������������������� 96 Usefulness of Implicitly Typed Local Variables������������������������������������������������������������������������������������� 97 C# Iteration Constructs��������������������������������������������������������������������������������������������������� 98 The for Loop������������������������������������������������������������������������������������������������������������������������������������������ 98 The foreach Loop���������������������������������������������������������������������������������������������������������������������������������� 99 Use of Implicit Typing Within foreach Constructs��������������������������������������������������������������������������������� 99 The while and do/while Looping Constructs�������������������������������������������������������������������������������������� 100 Decision Constructs and the Relational/Equality Operators����������������������������������������� 101 The if/else Statement������������������������������������������������������������������������������������������������������������������������� 101 Equality and Relational Operators������������������������������������������������������������������������������������������������������ 101 The Conditional Operator�������������������������������������������������������������������������������������������������������������������� 102 Logical Operators������������������������������������������������������������������������������������������������������������������������������� 103 The switch Statement������������������������������������������������������������������������������������������������������������������������� 103 Using Pattern Matching in Switch Statements (New)������������������������������������������������������������������������� 106 Summary���������������������������������������������������������������������������������������������������������������������� 109 ■Chapter ■ 4: Core C# Programming Constructs, Part II���������������������������������������� 111 Understanding C# Arrays���������������������������������������������������������������������������������������������� 111 C# Array Initialization Syntax�������������������������������������������������������������������������������������������������������������� 112 Implicitly Typed Local Arrays�������������������������������������������������������������������������������������������������������������� 113 x ■ INDEX Containment/delegation model GetBenefitCost(), 225–226 “is-a” relationship, 225 nested type definitions, 226 Content delivery networks (CDNs), 1187 Content layout, WPF controls content positioning Canvas panels, 1008 DockPanel, 1016 Grid panel, 1014 Grid splitters, 1015 ScrollViewer class, 1017 StackPanel, 1011 WrapPanel, 1009–1011 panel configuration, 1017 panel controls, 1008 ContentPresenter method, 1134 Controls, WPF documentation, 1005 Ink controls, 1004 OpenFileDialog box, 1004 SaveFileDialog box, 1004 Visual Studio designer Button control, 1005 ContentControl, 1006 document outline editor, 1006 Control template, 1130 ContentPresenter, 1134 element syntax, 1131 incorporating templates, 1134 internal controls, 1134 resources, 1131 {TemplateBinding} markup extension, 1133 visual cues importing, 1132 ControlTemplate class, 1127 C# operators overloading, 413 CoreCLR, 1249 CoreFX, 1249 C# parameter modifiers, 120 C# programming language anonymous types definition, 431 equality, 434 internal representation, 432 ToString() and GetHashCode() implementation, 434 conditional operator, 102–103 custom type conversions class types, 419 custom conversion routines, 420 explicit conversions, square type, 423 implicit conversion routines, 424 numerical conversions, 419 extension methods definition, 426 importing, 428 IntelliSense of, 428 interfaces, 429 invoking of, 427 if/else statement, 101 implicitly typed local variables 1358 DeclareExplicitVars() method, 94 DeclareImplicitVars() method, 95 restrictions, 95 strongly typed data, 96 uses, 97 indexer definition, interface types, 412 indexer methods, 407 multiple dimensions, 411 overloading, 411 string index values, 409 intrinsic data types, 68, 71 iterationconstructs (see C# iteration constructs) logical operators, 103 Main() method, 56 operatoroverloading (see Operator overloading, C#) pointertypes (see Pointer types, C#) relational/equality operators, 101 SimpleCSharpApp, 55–56 switchstatement (see Switch statement) System.Consoleclass (see System.Console class) system datatypes (see System data types) System.Environment class, 61–62 System.String basic string manipulation, 80 concatenation, 80 escape characters, 81 immutability, 85 members, 79 string and equality, 83 StringBuilder, 86–87 string interpolation, 87 verbatim string, 82 variable declaration, 69 Cross-language inheritance, 532 CurrentNumberChanged() method, 1058 Custom attributes AttributeTargets enumeration, 590 AttributeUsage, 590–591 class definitions, 589 CompanyInfoAttribute type, 599 creation, 588 named property syntax, 589–590 VehicleDescriptionAttribute, 588–589 CustomAttribute tokens, 566 Custom class library AssemblyInfo.cs file, 527 Car.cs, 522 CarLibrary.dll, 525 C# class library creation, 521 C# client application, 529–530 CIL, 527–528 cross-language inheritance, 532 DerivedCars.cs, 522 editing assembly information, 526 NET assemblies, 524 publickeytoken, 525 TurboBoost() method, 522 type metadata, 528 VB client application, 530–532 ■ INDEX Custom commands AddCarCommand class, 1167 ChangeColorCommand, 1168 MainWindow.xaml, 1168 ChangeColorCommand CanExecuteChanged event, 1165 MainWindow.xaml.cs, 1165 testing, 1166 update MainWindow.xaml, 1166 button controls, 1164 CommandBase class, 1167 creation, 1164 ICommand interface, 1164 RelayCommands, 1169 creation, 1169 delete car button, 1170 MainWindow.xaml.cs, 1170 RelayCommand creation, 1169 wrapping up, 1171 Custom generic methods default keyword, 359 DisplayBaseClass method, 356 structures and classes, 357–359 Swap method, 354, 356 type parameters, 356 Custom namespaces approaches, 509 Circle class, 510 default namespace, 515–516 NET *.dll assemblies, 509 fully qualified name, 511–512 My3DShapes namespace, 514–515 name clashes, aliases, 513 NET base class libraries, 510 ShapesLib.cs, 509 C# Windows OS NET Framework documentation system, 50–51 Visual Studio Community, IDE Class Designer Toolbox, 48 Class Details window, 47–48 class diagram file, 46 class diagram viewer, 47 class visualization, 49 Visual Studio Express, IDEs add reference, 44 object browser, 43 Project Properties window, 45 Solution Explorer, 42 „„         D Daemon threads, 722 Data access layer (DAL), 905, 1137 Database, 882 Data-binding model, WPF bound data formatting, 1046 CheckBox control, 1044 coding, 1048 DataContext property, 1045–1046 DataGrid control, 1049 DataGrid objects, 1044 initial layout, 1044 data conversion, IValueConverter interface, 1047 Label, 1044 Label’s Content property, 1045 Data provider factory model DbProviderFactory, 825 drawback, 828–829 , 829–830 Main() method, 826–827 System.Configuration.dll, 826 System.Data.Common namespace, 824 System.Data.OleDb, 827–828 Data type conversions Add() method, 89 checked keyword, 91 class program, 88–89 compiler error, 90 explicit cast, 90–91 implicit widening, 89 narrowing operation, 89 project-wide overflow/underflow data checking, 93 unchecked keyword, 93 DateTime type, 76 DbUpdateConcurrencyException, 899 DeclareImplicitVars() method, 95 Default access modifiers, 188 DefaultAppDomainApp AssemblyLoad event, 647 ListAllAssembliesInAppDomain(), 646–647 loaded assemblies, 646 Program class, 645 Default constructor, 71, 165 DefaultDeclarations() method, 70 Delegate BeginInvoke() and EndInvoke() methods, 706 BinaryOp, 703–704 console application program (SyncDelegateReview), 704, 705 Invoke() method, 704 synchronous manner, 704 System.IAsyncResult interface, 706 Delegate.Combine() method, 377 Delegate type BeginInvoke(), 367 BinaryOp class, 367, 370–372 delegate object, 371–372 EndInvoke(), 367 generic, 380–382, 384 Invoke(), 367 Main() method, 371 object state notifications Accelerate(), 374 CarDelegate, 373 CarEngineHandler, 374 method group conversion syntax, 379–380 multicast, 376–377 NullReferenceException, 375 1359 ■ INDEX Delegate type (cont.) OnCarEngineEvent(), 376 RegisterWithCarEngine(), 375 Remove(), 378–379 updates, 374 out/ref arguments, 368 pseudocode, 368 SimpleMath, 371 SquareNumber() method, 371 System.Delegate base classes, 369 System.MulticastDelegate, 366–367, 369 Delete() action method, 1191 Dependency injection (DI), 1285 DependencyProperty.Register() method, 1052–1053 Dequeue() method, 348 DirectoryInfo type Create() method, 758 CreateSubdirectory(), 761 Directory.Delete(), 761 Directory.GetLogicalDrives(), 761 DirectoryInfo.CreateSubdirectory(), 760 GetFiles() method, 759–760 key members, 758 Program class, 759 DisplayDefiningAssembly(), 427 DisplayDelegateInfo() method, 372 Dispose() method, 495–496 Distributed system, 907 DownloadStringAsync() method, 743 DriveInfo class type, 762–763 Dynamic Language Runtime (DLR) expression trees, 616–617 features, 615 System.Dynamic Namespace, 616 Dynamic loading assemblies Assembly.Load() method, 577 Assembly.LoadFrom(), 577 CarLibrary.dll, 577 DisplayTypes(), 575, 577 ExternalAssemblyReflector class, 575 System.Reflection, 575 {DynamicResource} markup extension, 1104 Dynamic types, pass arguments, 617 „„         E E-book, 744 Encapsulation automatic properties default values, 201 DisplayStats() method, 201 expected property syntax, 201 initialization of, 203–204 read-only automatic property, 200 syntax, 200 write-only property, 200 C# access modifiers, 188 C# class type car variable, 164 insertion, 162 member variables, 161 1360 objects allocation, 164 PrintState(), 163 SpeedUp(), 163 class definition, 190 constant field data, 208 constructors (see Constructors) int data type, 190 NET properties, 193 object initialization syntax custom constructors, 205 initializing data, 207 objectInitializers, 204 point objects, 205 partial classes, 211 private data, 190 properties, 196 read-only property, 198 static keyword importing static members, 183 static classes, 182 static constructors, 179 static field data, 176 static methods, 178 utility classes, 176 WriteLine() method, 176 static properties, 199 this keyword constructor chaining, 170 constructor flow, 173 IntelliSense, 170 Main() method, 169 optional arguments, 174 SetDriverName(), 169 traditional accessors and mutators, 191 write-only property, 198 EndInvoke() method, 367–368, 706 Enqueue() method, 348 EnterLogData() method, 128 Entity data model (EDM), 858 Entity Framework Core AutoLotDAL_Core2 AutoLotDAL_Core2 project vs EF 6, 1255 changes, 1256 Code First paradigm, 1256 features, 1256 usage scenarios, 1257 Entity Framework (EF), AutoLotConsoleApp ADO.NET EDM project item, 864 connection string, 866 database, 867–868 EDM generation, 865 SQL Server selection, 865 SuppressMessage attributes, 868 AutoLotEntities, 863 convention and configuration, 859 data annotations, 863 database, 858 DbContext class, 860–861 DbSet, 861 eager loading, 878–879 EDM, 858 ■ INDEX explicit loading, 879 interception, WriteInfo() method, 901 lazy loading, 877–878 LINQ queries, 857 LINQ to SQL, 858 mappings, 870–871 migrations creation, 888–889 credit risk class, 891 database update, 889 enabling, 888 EntityBase, 890 final migration, 891 Seed(), 893 TimeStamp property, 890 ObjectContext class, ObjectMaterialized event, 903 OnModelCreating(), 869 POCO classes, 859 runtime, 858 System.Data.Entity.dll, 860 transaction, 862 Enum.GetUnderlyingType() method, 137 Equality and relational operators, 101–102 ErrorTemplate, 1161 Escape characters, 81 Events Accelerate(), 386 add_Exploded(), 387 boilerplate code, 384 CarDelegate, 384 CarEngineHandler objects, 385 CarEvents, 386 C# 6.0 null-conditional operator, 391 custom event arguments, 392 generic EventHandler, 393 incoming events, 388–389 registration, 389, 391 remove_Exploded(), 387 ExecuteNonQuery() method, 837 ExecutePatternMatchingSwitch() method, 106–107 ExecuteReader() method, 837 Expression trees, 616–617 Extendable application building adding projects to solution, 599–600 assemblies, 597 CommonSnappableTypes.dll, 598 console application DisplayCompanyData() method, 605–606 IAppFunctionality, 605 LoadExternalModule() method, 604–605 Main() method, 606–607 C# snap-in, 601 multiproject ExtendableApp solution, 597 project build order context menu, 603 project references, adding, 600 setting project dependencies, 604 startup project, 602 Visual Basic snap-in, 601 Extensible Application Markup Language (XAML) property-element syntax, 973 WPF syntax attached properties, 982–983 Class and Member variable, 980 elements, 980 Kaxaml, 976–977 markup extensions, 983–984 property-element syntax, 981 type converter classes, 981 XML namespaces, 977–979 Extension methods, 430 „„         F Fiddler, 1231 FileAccess enumeration, 766 File-and Directory-centric types, 757 FileInfo.AppendText() method, 767 FileInfo class core members, 763 FileInfo.AppendText(), 767 FileInfo.Create() method, 764 FileInfo.CreateText(), 767 FileInfo.Open() method, 765–766 FileInfo.OpenRead(), 766 FileInfo.OpenText(), 767 FileInfo.OpenWrite(), 766 FileInfo.Create() method, 764 FileInfo.Open() method, 765–766 FileInfo.OpenText() method, 767 File I/O FileInfo.Create() method, 764 FileStream object, 764 MyFolder directory, 779 FileMode enumeration, 765 FileNotFoundException exception, 535 FileSystemInfo base class, 757 FileSystemInfo type, 756 FileSystemWatcher class, 779, 780 File type file-centric members, 768 FileStream examples, 768 methods, 769 Fill() method, 811 FillTheseValues() method, 122 Finalizable objects finalization process, 494 Finalize(), 491 garbage collector, 491 System.Object.Finalize(), 492–494 unmanaged resources, 492 Finalize() method, 491–493 foreach looping construct, 99 for loop, 98 FormatNumericalData()function, 66, 67 FrameworkElement type, 974 „„         G GC.Collect() method, 489 GC.SuppressFinalize() method, 498–499 1361 ■ INDEX Generic collections benefits, 337 type parameters class/structure, 339–340 constraints, 360 generic interfaces, 340 generic items, 337 generic members, 340 operator constraints, 362 where clause, 361 GetChildren() method, 1125 GetCoffee() funtion, 348 GetCommandLineArgs() method, 60 GetErrors() method, 1153 GetHashCode(), 434 GetStringArray() method, 116 GetValue() method, 1052 Global assembly cache (GAC), 26, 539–540 Globally unique identifier (GUID), 541 Graphical rendering, WPF adding rectangles, ellipses, and lines, 1064–1066 brushes and pens brush-derived types, 1072 code configuration, 1075–1076 configuration, VB, 1072–1074 configuring pens, 1076 drawings and geometries DrawingBrush, 1084 drawing-derived types, 1083–1084 painting, DrawingBrush, 1085 types, DrawingImage, 1086 graphicaltransformations (see Graphical transformations) options, 1062 path geometry-derived classes, 1069–1070 key members, 1068–1069 mini-language, 1070–1071 polylines and polygons, 1068 shape base class, 1063–1064 vector images event handler, 1088 graphic file into XAML, conversion, 1088 importing graphical data, WPF project, 1088 visual layer base class and derived child classes, 1089 custom layout manager, 1091–1093 DrawingVisual class, 1089–1091 hit-test operations, 1093–1094 Graphical transformations canvas data, 1078 Click event handler, 1078 , 1077 , 1078 RotateTransform object, 1077 ScaleTransform, 1077 transform-derived classes, 1076 undefined clipping region, 1079 Graphical user interface (GUI), 63, 736 1362 „„         H HelpExecuted() method, 1029 HTTPGet, 1227 HttpPost, 1234 HTTP verbs, 1227 „„         I IAppFunctionality interface, 598 IAsyncResult interface, 706 IDataErrorInfo, 1150 IDisposable, 495–496 if/else statement, 101 IgnoreRoute() method, 1191 Immediate-mode graphical systems, 1061 Index() action method, 1191 Indexer methods generic types, 409 interface definition, interface types, 412 multiple dimensions, 411 overloading, 411 PersonCollection class, 408 string values, 409 this keyword, 409 Inheritance BasicInheritance, 213 car class, 214 compiler error, 216 controlling base class, 221 Employee.cs and Employee.Core.cs files, 220 “is-a” relationship, 213 Manager class, 220 multiple base classes, 216 parent class, 214 protected keyword, 223 SalesPerson class, 220 sealed class, 224 sealed keyword, 216–217 Visual Studio class diagrams, 218–219 InitializeComponent() method, 1028 Ink API tab, WPF ComboBox control, 1041 handling events, 1038–1039 InkCanvas control, 1038–1041 layout, 1038 RadioButton controls, 1037 save and load, 1043–1044 toolbar designing, 1036–1037 Visual Studio toolbox, 1039 InsertAuto() method, 843 Interception AutoLotDAL, 900–901 DatabaseLogger interceptor, 902 IDbCommandInterceptor interface, 900 registering, 901–902 Interfaces abstract base classes, 286 abstract members, 283 arrays, 296–297 CloneMe(), 293 ■ INDEX cloning process, PointDescription type, 316 custom interfaces access modifier, 287 class/structure, 288 compiler errors, 287–288 IPointy, 287 namespace, 286 read-only property, 288 explicit interface implementation Draw() method, 299, 301 InterfaceNameClash, 299 Octagon type, 300 Hexagon type, 291 ICloneable interface, 311–313, 315–316 IComparable interface Car class, 317 CompareTo(), 318 custom static property, 320–321 definition, 316 internal CarID, 317 sort order, 319–320 System.Array class, 317 IDbConnection, 283 IDraw3D interface, 294–295 IEnumerable and IEnumerator array type, 305 Garage, 306 GetEnumerator(), 306, 309 IEnumerator type, 307 iterator method, 308–309 named iterators, 310–311 System.Collections namespace, 307 implementation, 288–290 InterfaceHierarchy BitmapImage, 302 drawing behavior, 302 IAdvancedDraw, 302 MIInterfaceHierarchy, 303–304 rendering-centric interfaces, 301 InvalidCastException, 291 is keyword, 292–293 method return values, 295–296 null reference, 291–292 ThreeDCircle and Hexagon, 293 types, 284–286 Visual Studio class diagram, 294 Visual Studio support, 297–298 Interlocked.CompareExchange() method, 730 Interlocked.Exchange() method, 729 Intermediate Language (IL), InventoryController class, 1197 create() methods, 1199 AntiForgery tokens, 1201 bind attribute, 1201 Get version, 1199 InventoryRepo, 1201 model binding, 1200 Post version, 1200 delete action, 1203 Get version, 1203 Post version, 1204 details action, 1198 double posts prevention, 1199 HttpPost vs HttpGet, 1199 PRG pattern, 1199 edit action, 1202 Get version, 1202 Post version, 1202 index action, 1198 inventory repository, 1197 Invoke() method, 367–368, 371 IsEvenNumber() method, 399 „„         J, K JavaScript Object Notation (JSON), 1228 Just-in-time (JIT) compiler, 3, 520 „„         L Lambda expressions arguments within multiple statements, 401–402 CarEvents, 404 expression-bodied members, 404–405 FindAll(), 398–400 multiple/zero parameters, 403 parameters, 401 Language Integrated Query (LINQ),5 See also LINQ programming model Late binding CreateUsingLateBinding() method, 582 invoke methods, parameters, 582–583 MethodInfo.Invoke(), 581 System.Activator class, 580–581 TurboBoost() method, 581, 582 VehicleDescriptionAttributeReader LateBinding, 594 LateBindingWithDynamic project, 618–619 LayoutTransform property, 1077 Lazy object instantiation, 501–505 LINQ programming model aggregation operations, 472 anonymous types, 449 C# LINQ query operators, 465–466 Count() extension method, enumerable class, 469 data types, 468 removing duplicate, 472 Reverse() extension method, 470 selection syntax, 466 sorting expression, 470 subsets of data, 467 Core LINQ assemblies, 450 data, API uses, 449–450 DataSet, 450 entities, 450 expressions, 450 extension methods, 448 lambda expressions, 447–448 local variables, 446 object and collection initialization syntax, 446 objects, 450 1363 ■ INDEX LINQ programming model (cont.) Parallel LINQ, 450 queries deferred execution, 458 enumerable type and anonymous methods, 476 enumerable type and lambda expressions, 474 enumerable type and raw delegates, 476 and extension methods, 457 filtering data, OfType( ), 464–465 immediate execution, role of, 459, 461–462 and local variables, 455–456 nongeneric collections, 463 query expression, 452–453 query operators, 474 QueryOverStrings() method, 451–454 QueryOverStringsWithExtension Methods(), 455 result set, 454, 460 subobjects access, 462–463 to SQL, 858 technology, 436 venn diagramming tool, 471 XML, 450 Loading process, 660 LocalNullableVariables() method, 151 LocalVarDeclarations() method, 70 Logical resources, 1095 application-level resources, 1105 element, 557 {DynamicResource} markup extension, 1104 merged resource dictionaries, 1106 resource-only assembly, 1107 Resources property, 1100 {StaticResource} markup extension, 1103 window-wide resources, 1100 „„         M Main() method, 56, 371, 826, 833 application error code, 58–59 asynchronous, 58 command-line arguments, 59–60 Program class, 56 setting command arguments, VS, 61 variations, 57 Managed code, MapRoute() method, 1191 Master parent class Main() method, 249 ObjectOverrides, 249 person class, 252 static members, 253 System.Object, 247–248, 250 System.Object.Equals(), 250 System.Object.GetHashCode(), 251 System.Object.ToString(), 250 Metadata, 14 Assembly token, 565 AssemblyRef #n token, 565 Car type, 564 EngineState enumeration, 562 1364 ildasm.exe, 562, 565 string literals, 566 TypeRef block, 565 Metadata exchange (MEX), 929 Method overloading Add(), 131–132 class definition, 131–132 intellisense list, 132 Method overriding, 229 Method parameter modifiers, 119 MethodWithProblems() method, 753 Microsoft.CSharp.dll assembly, 612–613 Microsoft Intermediate Language (MSIL), 10 Microsoft NET platform assembly, 22 assembly manifest, 14–15 base class libraries, CIL (see Common Intermediate Language (CIL)) CLI partitions, 31 CLR (see Common Language Runtime (CLR)) CLS (see Common Language Specification (CLS)) COM programming model, C# programming language, CTS, features, ildasm.exe, 28 CIL code, 29 manifest data, 30 metadata, 29 IL instructions and metadata, 10 managed vs unmanaged code, Mono project, 32 multilanguage applications, namespace programming, 22, 25–26 NET Core framework, 32 NET distributions, 31 NET namespaces, 24 root namespace, 25 Xamarin, 32 Microsoft Root namespace, 25 Migrate code and data control markup, 1172 MainWindow code and markup, 1172 MainWindow.xaml.cs code, 1171 view model, 1171 wrapping up, 1173 Minification, 1303 Model classes deleting records, 879 EF query execution, 876 EntityState, 881 inserting data, 872 inserting multiple records, 873 inserting record, 872–873 LINQ queries Find(), 876 PrintInventory(), 875 navigation properties, 877 eager loading, 878 explicit loading, 879 lazy loading, 878 ■ INDEX records selection, 874 remove multiple records, 880 SQL queries DbContext.Database, 875 DbSet, 874 update records, 881 Model-View-Controller (MVC), 1179 application template App_Start folder, 1186 ASP.NET folders, 1186 authentication options, 1182 Bootstrap, 1189 BundleConfig, 1187 bundling, 1187 content folder, 1188 controllers folder, 1185 FilterConfig, 1188 fonts folder, 1189 Global.asax.cs, 1185 IdentityConfig, 1188 minification, 1187 models folder, 1185 NuGet packages, 1190 project overview, 1183 project settings, 1190 project template, 1182 project wizard, 1181 root files, 1184 RouteConfig, 1188 scripts folder, 1189 shared folder, 1186 views folder, 1185 web application, 1181 AutoLotDAL, 1193 cconvention over configuration, 1181 controllers and actions, 1180 action results, 1194 inventory controller, 1194 InventoryController (see InventoryController class) model, context, and other options, 1196 Scaffold dialog box, 1196 wrapping up, 1204 definition, 1180 delete view, 1218 display data annotation, 1213 metadata files, 1213 forms, 1217 AntiForgeryToken() HTML helper, 1218 BeginForm() HTML helper, 1217 framework, 1180 layouts, 1210 menu options, 1211 page, 1210 specific page, 1211 model, 1179 partial views, 1211 routing, 1190 contact and about pages, 1192 redirection, 1192 route table, 1191 URL patterns, 1191 validation, 1218 client-side disable, 1219 client-side validation, 1219 errors, 1218 view, 1180 View() method, 1211 typed views and view models, 1212 ViewBag, ViewData, and TempData, 1212 Model-View-ViewModel (MVVM), 1137 anemic models/anemic view models, 1138 AutoLotDAL (see AutoLotDAL) model, 1137 view, 1138 view model serves, 1138 Module-level attributes, 591 Monitor.Enter() method, 728 Multithreaded application atomic and thread-volatile, 703 AutoResetEvent class, 721 background threads, 722–723 concurrency, 702–703 foreground threads, 722–723 Main() method, 724 ParameterizedThreadStart delegate, 720 PrintNumbers() method, 723–724 synchronization, 703 C# lock keyword, 726 [Synchronization] attribute, 730 System.Threading.Interlocked Type, 729 System.Threading.Monitor class, 728 System.Threading namespace, 701 static Thread.GetDomain() method, 702 ThreadStart Delegate, 718 thread synchronization, 724 MyEBookReader project, 742 MyResourceWrapper, 500 „„         N NarrowingAttempt() method, 91 Navigation properties, 877 Nested namespaces, 514 Nested types, 189 NET assemblies CIL Code, 520 CLR file header, 520 manifest, 521 private/shared, 518 promote code reuse, 517 satellite assemblies, 521 self-describing, 517 type boundary, 517 type metadata, 520 versionable units, 517 Windows file header, 518–519 NET attributes in C#, 585–586 CLS-compliant constructs, 584 constructor parameter, 587 custom attributes, 584 1365 ■ INDEX NET attributes (cont.) ildasm.exe, 586 notserialized token, 585 obsolete type, 587–588 predefined attributes, 584 reflection, binding, 593–594 serializable token, 585 shorthand attribute, 587 NET Core, 1245 CLI commands, 1250 composition CoreCLR, 1249 language compilers, 1250 SDK tools and dotnet app host, 1250 goals, 1246 command-line support, 1248 cross-platform support, 1247 interoperability, 1249 open source, 1249 performance, 1248 portable applications, 1248 portable class libraries, 1248 stand-alone deployments, 1248 installation, 1251 lifecycle Fast Track Support, 1251 Long Term Support, 1251 vs .NET framework, 1252 NETdelegate See Delegate NET framework, 1246 NET platform Process.Modules, 639 ProcessStartInfo, 641 ProcessThread, 637–639 ProcessThreadCollection, 637 running processes, 635 StartAndKillProcess(), 640, 642 starting and stopping processes, 640–641 static Process.GetProcessById() method, 636 System.Diagnostics namespace, 633–634 System.Diagnostics.process, 634–635 NET programming language, 657 Nongeneric collections issue of performance, 330 type safety, 333–336 Notification system, 1139 bindings and data, 1140 binding system, 1139 collections, 1144 dirty flag implementation, 1144 Fody package, 1147 ObservableCollections, 1144 PropertyChanged.Fody, 1146 UI interaction, 1146 UpdateSourceTrigger values, 1146 master-detail window, 1140 models, 1142 INotifyPropertyChanged interface, 1142 nameof method, 1144 observable models and collections, 1139 vehicle data, 1141 1366 wrapping up, 1147 Nullable data type, 150–154 Numerical format characters, 66 „„         O Object contexts automatic thread safety, 653 context-agile and context-bound types, 653 context-bound object, 654 inspection, 654 process/AppDomain/context relationship, 653 Object generations, 485 Object initialization syntax calling custom constructors, 205, 207 data initializing, 207 point objects, 205 Object lifetime application roots, 483 background garbage collection, 487 CIL newobj instruction, 481 concurrent garbage collection, 486 disposable objects, 494 finalizable and disposable types, 498 finalizable objects finalization process, 494 Overriding System.Object.Finalize(), 492 lazy object instantiation, 501 MakeACar() method, 481 object generations, 485 setting object references to null, 483 System.GC type garbage collection, 488 member selection, 487 ObjectMaterialized, 902–903 Object-oriented programming (OOP) encapsulation, 184 inheritance, 184–185 controlling base class, 221 Employee.cs and Employee.Core.cs files, 220 Manager class, 220 protected keyword, 223 SalesPerson class, 220 sealed class, 224 polymorphic abstract classes, 233 abstract methods, 237 Draw() method, 238 GiveBonus(), 228–229 Main() method, 239 sealing virtual members, 233 shadowing, 240 shapes hierarchy, 236 virtual and abstract methods, 236 virtual and override keywords, 229 Visual Studio IDE, 231 polymorphism, 186–187 Object-relational mapping (ORM) tools, 1144 Objectresource See Logical resources Object serialization ■ INDEX attributes, 800–801 formatter BinaryFormatter, 786–790 classes, 785 IFormatter and IRemotingFormatter interfaces, 786–787 SoapFormatter, 786–787, 790–791 type fidelity, 787–788 XmlSerializer, 786–787, 791–794 GUI-based desktop application, 781 ISerializable, 797–799 MyStringData, 799 object graphs, 782–783, 796 object set, 794 public fields, private fields, and public properties, 785 serializable types, 784 StreamingContextStates enumeration, 798 System.Object, 794 System.Runtime.Serialization namespace, 796 UserPrefs class, 781 ObjectStateEntry, 904 OnCarEngineEvent() method, 376 OnErrorsChanged() helper method, 1153 OnStart() method, 948 OnStop() method, 948 OnTransformDirty() method, 1053 Operational codes (opcodes) categorization, 678 implementation, 679 iteration constructs, 683–684 local variable declaration, 681–682 mapping parameters, 682 maxstack directive, 681 mnemonic distinction, 659–660 nonstatic method, 683 pop-centric, 680 primary stack-centric, 680 this reference, 682–683 Operator overloading, C# binary operators, 413 comparison operators, 418 equality operators, 417 MiniVan class, 419 += and–+ operators, 416 unary operators, 416 Out modifier, 121–122 „„         P, Q Parallel.Invoke() method, 745 Parallel LINQ (PLINQ), 701 Parallel LINQ queries (PLINQ) AsParallel() extension method, 746 cancellation, 746 description, 745 expensive/inexpensive parallel algorithm, 745 nonparallel version, 746 ParallelEnumerable Class, 745 Parallelprogramming See Task Parallel Library (TPL) ParameterizedThreadStart delegate, 718, 720–721 params modifier, 126 ParseFromStrings() method, 75 ParseFromStringWithTryParse() method, 75 Partial class, 211–212 Plain old CLR objects (POCOs), 1179 PLINQDataProcessingWithCancellation, 746 Pointer types, C# field access, 442 * and & operators, 440 pinning reference, 443 size of keyword, 444 stackalloc keyword, 442 unsafe (and safe) swap function, 441 unsafe keyword, 438 Polymorphism abstract classes, 233 GiveBonus(), 228–229 polymorphic interface abstract methods, 237 Draw() method, 237–238 Main() method, 239 shadowing, 240 shapes hierarchy, 236 virtual and abstract methods, 236 sealing virtual members, 233 virtual and override keywords, 229 Visual Studio IDE, 231 Post-Redirect-Get (PRG) pattern, 1199 Pre-WPF solutions, 966 Primary interop assembly (PIA), 622 PrintArray() method, 116 Private assemblies App.Config File, 536–538 CarLibrary.dll, 533 configuration, 534–535 identity, 533 probing process, 533 Private keys, 541 Probing, 533 ProcessFiles() method, 738, 741 Process.GetProcesses() method, 635 ProcessIntData() method, 747 Public keys, 541 Publisher policy assemblies, 555–556 „„         R Razor templates, 1214 custom display template, 1214 editor template, 1216 Razor view engine, 1205 built-in HTML helpers, 1206 delegates, 1209 EditorFor() method, 1207 edit template, 1207 functions, 1209 HTML helpers, 1208 HTML rendered, 1208 ShowInventory() method, 1208 SortCars() function, 1209 statements, code blocks and markup, 1205 syntax, 1205 ToList() method, 1209 Read() method, 835 1367 ■ INDEX Read-only field data, 209 Reference types assignment operator, 144–145 passing reference, 147–149 PointRef type, 145 Reflection attributes, late binding, 594 custom attributes, 593 GetInterfaces() method, 571 ListFields() method, 570–571 ListInterfaces() method, 571 ListMethods(), 570 Main() method implementation, 572 MethodInfo.Name property, 570 parameter types, 574 return types, 574 shared assemblies, 579 System.Collections.Generic.List, 573 System.Object.GetType() class, 568 System.Reflection namespace, 567 System.Type class, 567–568 System.Type.GetType() operator, 569 Type.GetMethods() method, 570 Type.GetType() method, 572, 573 typeof() operator, 568 RegisterWithCarEngine() method, 376 Remove() method, 378–379 RenderTransform property, 1077 Repository pattern Add() method, 896 BaseRepo, 894 delete records, 896 entity-specific repos, 897 IRepo interface, 893 retrieve records, 895 retrieve records with SQL, 895 SaveChanges(), 894 update records, 896 ResetPoint() method, 358 Resource system binary resources application resources, 1099 configuration of loose resources, 1097 embedded resources, 1099 icons and image files, 1095 image loading, 1097 loose files, 1097 output directories, 1097 logicalresources (see Logical resources) Retained-mode graphics, 1061 ReverseDigits() method, 426 Rollback() method, 848 Roslyn, 1250 Round-trip engineering assembly, 663 branching/looping constructs, 665 C# class definition, 667 C# console app., 662 CIL compiler, 662 CIL directives, 664 code labels, 665 default constructor, 663–664 1368 HelloProgram.il file, 663, 667 *.il file, 665–666 ilasm.exe, 667–668 ildasm.exe, 662 load-centric, 664 mscorlib, 666 opcodes, 664 peverify.exe, 668 program class, 663 techniques, 662 Runtime Callable Wrapper (RCW), 622 „„         S SavingChanges, 903–904 SendAPersonByReference() method, 149 Service-oriented architecture (SOA), 909 SetBinding() method, 1051 SetF1CommandBinding() method, 1028 SetValue() method, 1052 Shared assemblies configuration client *.config file, 550 freezing, current shared assembly, 551 shared assembly version 2.0.0.0, 552–553 SharedCarLibClient.exe.config, 554–555 side-by-side execution, 553 consumption, 548, 550 global assembly cache, 539–540 mscorlib.dll, 538 strong names assembly-level attributes, 541 command line, 542–544 GAC, 546–547 GUID, 541 public and private key data, 542 publickey token, 541 Visual Studio, 544–545 ShowDialog() method, 1004 ShowEnvironmentDetails()method, 61 SimpleArrays() method, 111 SimpleBoxUnboxOperation() method, 330 Simple Object Access Protocol (SOAP), 790 SoapFormatter, 786–787, 790–791 SqlBulkCopy custom data reader, 853–854 execution, 855–856 test, 856 WriteToServer() and WriteToServerAsync(), 852 SQL server express, 905–906 SquareNumber() method, 371 Stack-based programming language, 660 STAThread attribute, 607 static keyword importing static members, 183 static classes, 182 static constructors, 179–181 static field data, 176–177 static methods, 178–179 utility classes, 176 Static method, 372 ■ INDEX Static read-only fields, 210–211 {StaticResource} markup extension, 1103 Storing, 660 StreamWriter and StreamReader classes core members, TextWriter, 772 creating, 775 strings, 772 text file reading, 774–775 writing, 773–774 StringBuilder, 86–87 StringComparison option, 84 String concatenation, 80 StringConcatenation() function, 80 String.Format() method, 67 String interpolation, 87–88 StringsAreImmutable2() method, 85 StringWriters and StringReaders, 775–776 Structured exception handling Accelerate() method, 261 application-level exceptions, 268 attributes/object serialization, 272 CarIsDeadException, 269–271 code snippet template, 272–273 custom exception, 269 prim-and-proper custom exception class, 272 ArgumentOutOfRangeException, 273 bugs, 255 catch logic, 273 catch statements, 276 compile-time errors, 275 constructors, 259–260 containment/delegation, 259 data property, 266–268 debugging, 280–281 definitions, 255 filters, 279 HelpLink property, 265–266 inner exceptions, 277–278 NET building blocks, 257 C code, 256 E_FILENOTFOUND constant, 256 System.Exception base class, 257–258 WCF service, 257 Radio type, 259 rethrowing exceptions, 276–277 StackTrace property, 265 system exceptions, 268 TargetSite property, 264 try/catch block, 262–263, 278 user errors, 255 verbose error dump, 262 Styles assigning style, 1122 animation sequence, 1122 App.xaml file, 1117 BasedOn, 1116 controls, 1119 definition, 1117 effect of TargetType, 1118 multiple triggers, 1121 overriding, 1117 subclassing exist, 1119 TargetType, 1116 triggers, 1116, 1120 Subtract() method, 372 svcutil.exe, 932–933 Switch statement, 104 case statements, 106, 108 data types, 104 ExecutePatternMatchingSwitch(), 106–107 goto statement, 106 string variable, 104 System.DayOfWeek enum, 104–105 type pattern, 106 System.Array class, 117 System.Boolean data type, 74 System.Char type, 74 System.Collections.Generic classes, 343 collection initialization syntax, 343–344 Dictionary type, 350 interfaces, 342 List class, 345–346 Queue class, 347–348 SortedSet class, 348 Stack class, 346–347 System.Collections.ObjectModel members, 351 ObservableCollection class, 352 System.Configuration namespace, 558–559 System.Console class formatting Console.WriteLine(), 65 numerical data, 65 String.Format() method, 67 input and output, 63–64 members, 63 System data types BigInteger data type, 76 binary literals, 79 class hierarchy, 72 digit separator, 78 intrinsic data types, 71 numerical system type, 73 parsing values, 75 System.Boolean, 74 System.Char type, 74 System.DateTime, 76 System.Numerics.dll assembly, 77 System.TimeSpan, 76 TryParse() method, 76 System.Dynamic namespace, 616 System.Environment class properties, 62 ShowEnvironmentDetails() method, 61 System exceptions, 268 System.GC type garbage collection, 488–489, 491 Main() method, 488 members selection, 487 System.IO namespace, 755 System.IO.Stream class, 770 1369 ■ INDEX System.Numerics namespace, 76–77 System.Reflection, 1128 System.Runtime.Remoting.Contexts namespace, 730 System.Threading namespace CLR-maintained thread pool, 713 core types, 714 current thread execution, 715–716 debugging, Visual Studio, 717 multithreaded applications, 713 Name property, 716 object-oriented wrapper, 714 Priority property, 717 steps, 718 thread type instance-level members, 715 static members, 714 System.Threading namespace CLR thread pool, 733 System.ValueType, 143 System.Windows.Controls namespace, 1007 System.Windows.Markup, 1128 System.Windows.Window class, 971 „„         T Tag helpers, 1288 Anchor tag helper, 1291 built-in tag helpers, 1289 custom tag helpers, 1295–1296 @addTagHelper command, 1296 Environment tag helper, 1294 Form tag helper, 1291 vs HTML helpers, 1288 HTML5 type attributes, 1292 Image tag helper, 1294 Input tag helper, 1291 Link and Script tag helpers, 1294 Select tag helper, 1293 TextArea tag helper, 1292 Validation tag helpers, 1293 Task Parallel Library (TPL), 701, 703, 710 accessing UI elements, 739–740 cancellation tokens, 740–742 data parallelism, 736–739 multithreaded application, 734 Parallel class, 735–736 System.Threading.Tasks namespace, 735 Task class, 740 task parallelism, 742 threading toolkits, 734 Thread, 701 Thread affinity, 739 Thread Local Storage (TLS), 633 Thread management, 734 ThreadPool.QueueUserWorkItem() method, 733 Thread.Sleep() method, 704 static Thread.Sleep() method, 705 Thread.Start() method, 722 ThreadStart delegate, 718–720 ThreadStats, 715 Thread synchronization, 703 1370 Timer callbacks configuration, 731 null value, 732 PrintTime() method, 731–732 stand-alone discard, 732 Timer type, 731 Timestamp, 899 ToArray() extension method, 469 ToolsSpellingHints_Click() method, 1025 Trigger framework, 1130 TryFindResource() method, 1123 TryParse() statement, 75 Tuples deconstructing, 157 discards, 157 inferred variable names, 156 method return values, 156 parenthetical construct, 155 values variable, 155 ValueTuple data type, 154 TurboBoost() method, 522–523 Type.GetCustomAttributes() method, 594 Type.GetType() method, 569 „„         U UIElement type, 975 Unboxing, 330 Unmanaged code, Update() methods, 811 Upsert, 885 „„         V ValidateCurrentNumber method, 1057 Validations, 1148 class, 1148 data annotations errors, 1159 project reference, 1159 default error template, 1149 ErrorTemplate, 1161 IDataErrorInfo, 1150 INotifyDataErrorInfo, 1152 base class, 1158 code implementation, 1153 IDataErrorInfo, 1155 ModelT validation, 1154 notify on exceptions, 1149 options, 1149 WpfValidations, 1148 wrapping up, 1163 ValueAndReferenceTypes() method, 143 Value types assignment operator, 143–144 passing reference, 147–148 Rectangle type, 146 reference types, 145, 146 System.ValueType, 143 ValueTypeAssignment() method, 145 Verbatim string, 82 ■ INDEX Virtual execution stack, 660 Virtual member, 186 Visual class designer, 46–49 Visual State Manager (VSM), 1130 Visual Studio 2017 building NET applications, 39–40 C# 7.1 features add reference, 44 class designer toolbox, 48 class details window, 47–48 class diagram file, 46 class diagram viewer, 47 object browser, 43 project properties window, 45 running and debugging, 41 solution explorer, 42 components, 38 enterprise, 50 installation process, 36–37 professional editions, 50 workloads selection, 38 Visual Studio transform editor building initial layout, 1080–1081 Canvas in code, 1083 transformations, design time, 1081–1082 „„         W WCF See Windows Communication Foundation (WCF) WcfTestClient.exe, 912 Web API project, empty project template, 1224 Web applications, ASP.NET Core, 1279 AutoLotMVC_Core2 application, 1296 DAL, 1281 dependency injection, 1285 deployment target, 1284 environment-based configuration system, 1285 application configuration, 1286 connection strings, 1287 retrieving settings, 1287 runtime environment, 1286 execution, 1282 improvements and innovations, 1284 MVC project template, 1281 NuGet packages, 1282 principles client-side frameworks, 1288 lightweight and modular HTTP request pipeline, 1288 tag helpers, 1288 project wizard, 1279 Razor view engine, 1296 templates, 1280 view components, 1296 Visual Studio debugging profiles, 1283 Windows Communication Foundation (WCF), 3, 257, 560–561, 910, 1223 address, 914, 918 AutoMapper Nuget package, 959 binding, 914 characteristics, 916 HTTP-Centric, 916 MSMQ-Centric, 918 TCP-Centric, 917 client, 913–914 client-side proxy configuration, 955 configuration settings client proxy refreshment, 935, 942 default endpoints, 937 MEX service behavior, 941 multiple endpoints, 938 WCF binding, 940 contract, 914–915 data contracts, 956 features, 908 hosting base addresses specification, 925 configuration, 923 definition, 922 Element, 928 metadata exchange (MEX), 929 ServiceHost type, 924, 926–927 service.serviceModel, 928 TCP based binding, 935 MagicEightBallService, 920 MathService, 954 namespaces, 911, 919 NET assemblies, 911 OperationContract attribute, 921–922 proxy code svcutil.exe, 932–933 Visual Studio, 933–934 service assembly, 913 ServiceContract attribute, 921 service host, 913 service interfaces, [ServiceContract] attribute, 921 Service Library project MathServiceLibrary, 944 SvcConfigEditor.exe, 945–947 WcfTestClient.exe, 945 service-oriented architecture, 909 service testing, 962 *.svc File, 960 Visual Studio, 912 Visual Studio web-based project template, 913 web-centric service, 957 Web.config File, 961 Windows service hosting ABCs specification, 948 creation, 948 enabling MEX, 950 installation, 952 Windows service installer, 950 Windows OS thread scheduler, 702 Windows Presentation Foundation (WPF), 3, 736 advantage, 966 Application Class, 970 Application.Windows collection, 971 assemblies, 968 commands (see Commands, WPF) controls (see Controls, WPF) custom dependency property Content property, 1055 1371 ■ INDEX Windows Presentation Foundation (WPF) (cont.) CurrentNumber property, 1056 data validation, 1057 property change, 1058 ShowNumberControl.xaml, 1054 UserControl types, 1055 default template, 1127 dependency properties benefits, 1050 CLR property wrappers, 1054 custom control, 1051 definition, 1050 Height property, 1051 implementation, 1050 SetBinding() method, 1051 desired functionalities, 966 3D functionality, 966 documentation, 1000 document controls, 1004 features, 967 logical tree, 1125 namespaces, 969 rendering model, 967 resourcesystem (see Resource system) routed events bubbling events, 1032 tunneling events, 1033 styles (see Styles) TabControl, 1035 UI programming, 967 Visual Studio application-level data, 997 App.xaml File, 993–994 BAML role, 996 Button and Calendar control, 987 debugger, 992 Document Outline Window, 991 drag-and-drop operation, 987 keyboard events, 1000 Main() method, 996 mouse events, 999 project templates, 985 Properties window, 988 toolbox, 987 Window designer, 988 window object closing, 998–999 Window XAML Markup to C# Code, 994–996 visual tree, 1127 1372 Window class, 972 System.Windows.Controls.ContentControl, 972 System.Windows.Controls.Control, 973 System.Windows.DependencyObject, 975 System.Windows.FrameworkElement, 974 System.Windows.Media.Visual, 975 System.Windows.Threading.DispatcherObject, 975 System.Windows.UIElement, 974 Window’s frame, nested panels menu system, 1021 MouseEnter handler, 1025 MouseExit handler, 1025 MouseLeave handler, 1025 spell checker, 1025 StatusBar, 1024 ToolBar, 1023 UI design, 1024 XAML attached properties, 982 child element, 980 ClassModifier and FieldModifier keywords, 980 elements, 980 Kaxaml, 976 keywords, 979 layout managers, 980 markup extensions, 983 property-element syntax, 981 type converter classes, 981 XML namespaces, 977, 979 Windows process concept of, 631 threads, role of, 632 unique process identifier, 631 Windows Task Manager, 632 WithCancellation() extension method, 747 „„         X, Y, Z Xamarin, 32 XamlAnimations BeginAnimation() method, 1113 discrete key frame, 1115 event triggers, 1115 GrowLabelFont.xaml file, 1114 storyboards, 1114 XAML editor, events handling, 990 XmlSerializer, 785–787, 791–794 .. .Pro C# With NET and NET Core Eighth Edition Andrew Troelsen Philip Japikse Pro C# 7: With NET and NET Core Andrew Troelsen Philip Japikse Minneapolis, Minnesota, USA West Chester, Ohio,... (pbk): 978 -1-4842-30 17- 6 https://doi.org/10.10 07/ 978 -1-4842-3018-3 ISBN-13 (electronic): 978 -1-4842-3018-3 Library of Congress Control Number: 20 179 5 871 7 Copyright © 20 17 by Andrew Troelsen and. .. (son) We miss you, Mikko (the cat) —Andrew To my family, Amy (wife), Conner (son), Logan (son), and Skylar (daughter), thank you for all of the support and patience you have given me —Philip Contents

Ngày đăng: 25/02/2023, 18:04

Tài liệu cùng người dùng

Tài liệu liên quan