Professional Documents
Culture Documents
Textbook Pro C 7 With Net and Net Core Andrew Troelsen Ebook All Chapter PDF
Textbook Pro C 7 With Net and Net Core Andrew Troelsen Ebook All Chapter PDF
NET Core
Andrew Troelsen
Visit to download the full and correct content document:
https://textbookfull.com/product/pro-c-7-with-net-and-net-core-andrew-troelsen/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://textbookfull.com/product/pro-c-8-with-net-
core-3-foundational-principles-and-practices-in-programming-
ninth-edition-andrew-troelsen/
https://textbookfull.com/product/pro-c-9-with-net-5-foundational-
principles-and-practices-in-programming-tenth-edition-andrew-
troelsen-phillip-japikse/
https://textbookfull.com/product/pro-c-9-with-net-5-foundational-
principles-and-practices-in-programming-tenth-edition-andrew-
troelsen-phillip-japikse-2/
https://textbookfull.com/product/building-microservices-with-net-
core-2-0-transitioning-monolithic-architectures-using-
microservices-with-net-core-2-0-using-c-7-0-gaurav-aroraa/
C 8 0 and NET Core 3 0 Modern Cross Platform
Development Build applications with C NET Core Entity
Framework Core ASP NET Core and ML NET using Visual
Studio Code 4th Edition Mark J. Price
https://textbookfull.com/product/c-8-0-and-net-core-3-0-modern-
cross-platform-development-build-applications-with-c-net-core-
entity-framework-core-asp-net-core-and-ml-net-using-visual-
studio-code-4th-edition-mark-j-price/
https://textbookfull.com/product/modern-data-access-with-entity-
framework-core-database-programming-techniques-for-net-net-core-
uwp-and-xamarin-with-c-1st-edition-holger-schwichtenberg/
https://textbookfull.com/product/modern-data-access-with-entity-
framework-core-database-programming-techniques-for-net-net-core-
uwp-and-xamarin-with-c-1st-edition-holger-schwichtenberg-2/
https://textbookfull.com/product/pro-asp-net-core-identity-under-
the-hood-with-authentication-and-authorization-in-asp-net-
core-5-and-6-applications-1st-edition-adam-freeman/
https://textbookfull.com/product/c-7-and-net-core-modern-cross-
platform-development-2nd-edition-mark-j-price/
Pro C# 7
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 ISBN-13 (electronic): 978-1-4842-3018-3
https://doi.org/10.1007/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
Contents at a Glance
■
■Part I: Introducing C# and the .NET Platform������������������������������������� 1
■
■Chapter 1: The Philosophy of .NET������������������������������������������������������������������������� 3
■
■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
■
■Part I: Introducing C# and the .NET Platform������������������������������������� 1
■
■Chapter 1: The Philosophy of .NET������������������������������������������������������������������������� 3
An Initial Look at the .NET Platform��������������������������������������������������������������������������������� 3
Some Key Benefits of the .NET Platform������������������������������������������������������������������������������������������������ 4
Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS)���������������� 4
The Role of the Base Class Libraries������������������������������������������������������������������������������������������������������ 5
What C# Brings to the Table������������������������������������������������������������������������������������������������������������������� 5
Managed vs. Unmanaged Code�������������������������������������������������������������������������������������������������������������� 8
vii
■ Contents
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
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
ix
■ Contents
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
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
■ Contents
xi
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 158
■
■Part III: Object-Oriented Programming with C#������������������������������ 159
■
■Chapter 5: Understanding Encapsulation���������������������������������������������������������� 161
Introducing the C# Class Type�������������������������������������������������������������������������������������� 161
Allocating Objects with the new Keyword������������������������������������������������������������������������������������������ 164
xii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 212
■
■Chapter 6: Understanding Inheritance and Polymorphism�������������������������������� 213
The Basic Mechanics of Inheritance���������������������������������������������������������������������������� 213
Specifying the Parent Class of an Existing Class�������������������������������������������������������������������������������� 214
Regarding Multiple Base Classes������������������������������������������������������������������������������������������������������� 216
The sealed Keyword��������������������������������������������������������������������������������������������������������������������������� 216
xiii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 254
■
■Chapter 7: Understanding Structured Exception Handling�������������������������������� 255
Ode to Errors, Bugs, and Exceptions���������������������������������������������������������������������������� 255
The Role of .NET Exception Handling��������������������������������������������������������������������������� 256
The Building Blocks of .NET Exception Handling�������������������������������������������������������������������������������� 257
The System.Exception Base Class������������������������������������������������������������������������������������������������������ 257
xiv
■ Contents
xv
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 321
■
■Part IV: Advanced C# Programming����������������������������������������������� 323
■
■Chapter 9: Collections and Generics������������������������������������������������������������������ 325
The Motivation for Collection Classes�������������������������������������������������������������������������� 325
The System.Collections Namespace�������������������������������������������������������������������������������������������������� 327
A Survey of System.Collections.Specialized Namespace������������������������������������������������������������������� 329
xvi
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 363
■
■Chapter 10: Delegates, Events, and Lambda Expressions��������������������������������� 365
Understanding the .NET Delegate Type������������������������������������������������������������������������ 365
Defining a Delegate Type in C#����������������������������������������������������������������������������������������������������������� 366
The System.MulticastDelegate and System.Delegate Base Classes�������������������������������������������������� 369
xvii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 406
■
■Chapter 11: Advanced C# Language Features��������������������������������������������������� 407
Understanding Indexer Methods���������������������������������������������������������������������������������� 407
Indexing Data Using String Values������������������������������������������������������������������������������������������������������ 409
Overloading Indexer Methods������������������������������������������������������������������������������������������������������������� 411
Indexers with Multiple Dimensions���������������������������������������������������������������������������������������������������� 411
Indexer Definitions on Interface Types������������������������������������������������������������������������������������������������ 412
xviii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 444
■
■Chapter 12: LINQ to Objects������������������������������������������������������������������������������� 445
LINQ-Specific Programming Constructs����������������������������������������������������������������������� 445
Implicit Typing of Local Variables������������������������������������������������������������������������������������������������������� 446
Object and Collection Initialization Syntax����������������������������������������������������������������������������������������� 446
xix
■ Contents
xx
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 478
■
■Chapter 13: Understanding Object Lifetime������������������������������������������������������� 479
Classes, Objects, and References�������������������������������������������������������������������������������� 479
The Basics of Object Lifetime��������������������������������������������������������������������������������������� 480
The CIL of new������������������������������������������������������������������������������������������������������������������������������������ 481
Setting Object References to null������������������������������������������������������������������������������������������������������� 483
Summary���������������������������������������������������������������������������������������������������������������������� 505
xxi
■ Contents
■
■Part V: Programming with .NET Assemblies����������������������������������� 507
■
■Chapter 14: Building and Configuring Class Libraries��������������������������������������� 509
Defining Custom Namespaces������������������������������������������������������������������������������������� 509
Resolving Name Clashes with Fully Qualified Names������������������������������������������������������������������������ 511
Resolving Name Clashes with Aliases������������������������������������������������������������������������������������������������ 513
Creating Nested Namespaces������������������������������������������������������������������������������������������������������������ 514
The Default Namespace of Visual Studio�������������������������������������������������������������������������������������������� 515
xxii
■ Contents
xxiii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 607
■
■Chapter 16: Dynamic Types and the Dynamic Language Runtime�������������������� 609
The Role of the C# dynamic Keyword��������������������������������������������������������������������������� 609
Calling Members on Dynamically Declared Data�������������������������������������������������������������������������������� 611
The Role of the Microsoft.CSharp.dll Assembly���������������������������������������������������������������������������������� 612
The Scope of the dynamic Keyword��������������������������������������������������������������������������������������������������� 613
Limitations of the dynamic Keyword�������������������������������������������������������������������������������������������������� 614
Practical Uses of the dynamic Keyword��������������������������������������������������������������������������������������������� 614
Summary���������������������������������������������������������������������������������������������������������������������� 629
xxv
■ Contents
■
■Chapter 17: Processes, AppDomains, and Object Contexts������������������������������� 631
The Role of a Windows Process����������������������������������������������������������������������������������� 631
The Role of Threads���������������������������������������������������������������������������������������������������������������������������� 632
xxvi
■ Contents
.NET Base Class Library, C#, and CIL Data Type Mappings������������������������������������������� 675
Defining Type Members in CIL�������������������������������������������������������������������������������������� 675
Defining Field Data in CIL������������������������������������������������������������������������������������������������������������������� 676
Defining Type Constructors in CIL������������������������������������������������������������������������������������������������������� 676
Defining Properties in CIL������������������������������������������������������������������������������������������������������������������� 677
Defining Member Parameters������������������������������������������������������������������������������������������������������������� 678
xxvii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 698
■
■Part VI: Introducing the .NET Base Class Libraries������������������������� 699
■
■Chapter 19: Multithreaded, Parallel, and Async Programming������������������������� 701
The Process/AppDomain/Context/Thread Relationship������������������������������������������������ 701
The Problem of Concurrency�������������������������������������������������������������������������������������������������������������� 702
The Role of Thread Synchronization��������������������������������������������������������������������������������������������������� 703
xxviii
■ Contents
xxix
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 754
■
■Chapter 20: File I/O and Object Serialization���������������������������������������������������� 755
Exploring the System.IO Namespace��������������������������������������������������������������������������� 755
The Directory(Info) and File(Info) Types������������������������������������������������������������������������ 756
The Abstract FileSystemInfo Base Class�������������������������������������������������������������������������������������������� 757
Summary���������������������������������������������������������������������������������������������������������������������� 801
■
■Chapter 21: Data Access with ADO.NET������������������������������������������������������������� 803
A High-Level Definition of ADO.NET������������������������������������������������������������������������������ 803
The Three Faces of ADO.NET�������������������������������������������������������������������������������������������������������������� 804
xxxi
Another random document with
no related content on Scribd:
vaiti, vaikkakin hänellä oli sentnerin paino omallatunnollaan.
Seuraus siitä oli, että ne työt, jotka vielä saatiin, lyötiin laimin
eivätkä valmistuneet oikeaan aikaan.
"Hanna", sanoi hän sitte, "mitä siitä sitte tulee, kun Vilhelm palaa?
Vannon teille, että olen teidän totinen ystävänne, mutta juuri siksi
täytyy minun katsoa tulevaisuuteen teidän puolestanne. Miehenne
on ainaiseksi kunniaton mies, ja vaikkei tänään kukaan voi sälyttää
hänen rikostaan teidän eikä lastenne hartioille, niin tehdään se
silloin, kun hän on jälleen luonanne, Hanna, teidän täytyy —"
Tämä oli se Marat toisen suunnitelma. Hän oli usein ajatellut tätä
kiristyskoetta, nähdessään kuinka puotikassa pysyi yhä tyhjänä ja
velat lisääntyivät, mutta ensin tahtoi hän nähdä saiko agitaattori
tosiaankin valtikan käsiinsä.
Ja nyt oli aika tullut, nyt oli hätä kynnyksellä, nyt oli joko taivuttava
tai taituttava. Nyt sai tämä porvari vetää kassansa esiin, kuten hän
kerran oli imenyt Schornia kaikella hienostuneella viekkaudellaan.
"Kuritushuoneeseen tulee hän sentään kyllin aikaiseen", täten
koetti herra Pätzoldt puolustaa attentaattiaan, jonka hän oikeastaan
teki Schornin omaisuutta vastaan.
Sepäs vielä puuttui, että häneltä nyt riistettäisiin ihanat päivät! Nyt
kun hän puhetaiteellaan oli saanut asiat niin pitkälle, että hänen
lemmittynsä oli taipuvainen ennen pitkää myymään talon ja tavarat,
lähteäksensä hänen kanssansa Ameriikkaan. Ja tämän kurjan
kääpiön täytyi kaikkialle tulla hänen tielleen. Mutta hänen turpansa
täytyi tukkia, sitte sai toistaiseksi olla rauhassa.
Rouva Schorn sanoi vaan pari sanaa, käskien hänen tehdä miten
hyväksi katsoo. Hän jätti jo kotiystävälle vapaat kädet.
Kadulta ei hän tahtonut astua taloon, ei, kuten varas tahtoi hän
hiipiä puutarhan aitovartta pitkin, kaikkien näkemättä, tuntematta,
ensin seistä kotvan aikaa mykkänä, kädet ristissä kotiaan katsellen;
rukoilla Jumalalta rohkeutta seuraavaa hetkeä varten.
Hän ei voinut uskoa, mitä oli kuullut, tai —? Hän ei voinut selvästi
ajatella, hänen ohimoissaan kihisi ja kiehui.
Niin, nyt uskoi hän kaiken, mitä hulttio maantiellä oli hänelle
kertonut.
*****