Instant Download Pro C# 7 With .NET and .NET Core Andrew Troelsen PDF All Chapter
Instant Download Pro C# 7 With .NET and .NET Core Andrew Troelsen PDF All Chapter
com
https://textbookfull.com/product/pro-c-7-with-net-
and-net-core-andrew-troelsen/
https://textbookfull.com/product/pro-c-8-with-net-core-3-foundational-
principles-and-practices-in-programming-ninth-edition-andrew-troelsen/
textbookfull.com
https://textbookfull.com/product/understanding-the-modern-world-david-
ferriby/
textbookfull.com
https://textbookfull.com/product/decentralization-regional-diversity-
and-conflict-the-case-of-ukraine-hanna-shelest/
textbookfull.com
https://textbookfull.com/product/gender-and-the-nuclear-family-in-
twenty-first-century-horror-1st-edition-kimberly-jackson-auth/
textbookfull.com
The AI Advantage How to Put the Artificial Intelligence
Revolution to Work 1st Edition Thomas H. Davenport
https://textbookfull.com/product/the-ai-advantage-how-to-put-the-
artificial-intelligence-revolution-to-work-1st-edition-thomas-h-
davenport/
textbookfull.com
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
[email protected], 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 [email protected], 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
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
■ 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
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
■ 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
Random documents with unrelated
content Scribd suggests to you:
I am, etc.
319
W. Pulteney.
Few persons did understand his conduct, and sensitive pride kept
his lips sealed. Nevertheless to all unprejudiced minds his conduct
needed no defence. On that higher plane where truth and justice are
alone considered (for justice is applied truth), Pitt did not swerve from
the principles which he at first laid down. From the beginning of the
Hastings case he had sought to hold the balances even. He left it open
to his colleagues to differ from him. He refused the publication of
papers favourable to Hastings where they compromised the welfare of
the State or the characters of our Indian feudatories. He insisted that
the charges against Hastings should be clearly drawn up, and that he
should be allowed to answer those charges in person. On the topic of
the Rohilla War he did not speak, doubtless because his mind was not
made up. The fact that Parliament had three times re-appointed
Hastings after that very censurable event, did in a technical sense
screen him from prosecution now. But on the Benares affair, no such
plea could be urged. It was a question on which the present Parliament
alone had to decide.
The enormous vogue enjoyed by Macaulay’s Essays compels me
once more to notice his treatment of Pitt respecting the Benares
charge. A man of philosophic temperament once expressed a wish
that he was as sure about anything, as the great Whig historian was
about everything. This assertiveness peeps through the veil of
diffidence which Macaulay donned before delivering the verdict, that
any man with a tenth part of Pitt’s abilities ought to have convicted
Hastings on the Rohilla charge and acquitted him on the Benares
320
charge. In order to establish this assertion Macaulay passed by the
technical plea above named, which must have weighed with Pitt, and
then used his powers of special pleading to whittle down Pitt’s
arguments on the Benares case, so that they seem to turn ultimately
on the trumpery question whether the fine inflicted on the Zamindar
was rather too large or not. But we may ask, firstly, was it a small affair
to exact half a million sterling from a prince who during three years had
been hard pressed, and as a matter of fact had paid up the arrears for
which that fine was imposed? Did it concern the Zamindar alone? Did
it not concern all the subjects from whom that half million must
ultimately be wrung?
Not only did the conduct of Hastings far exceed the limits required
by justice; it was also bound up with a question on which the stability of
our Indian Empire has ever rested. So long as the feudatories of the
British Raj feel confidence in his sense of justice, India is safe.
Whenever they have cause to believe that injustice and oppression are
the characteristics of his rule, the foundations of the Indian Empire are
shaken to their base. Not without reason did Fox declare that the
decision on the Benares affair was vital to the preservation of our
ascendancy in Bengal. The statesmanlike eye of Pitt, we may be sure,
discerned the same truth. Besides, there was an additional reason why
he should now more than ever resolve to engrave the names of Justice
and Mercy on the newly formed arch of the Indian Government. As has
been shown, the recent India Bill placed greatly increased powers in
the hands of the Governor-General. Burke and Fox had taunted Pitt
with setting up a despotism from which endless suffering must flow.
The charge was hollow; but, adorned as it was by splendid rhetoric, it
created a deep impression. Was it not well, then, to show by a
concrete example that any Viceroy who violated the principles of
justice would meet with condign punishment at Westminster? A
statesman has to consider, not merely the principles of justice, as
applied to an individual; he must also think of the results of his actions
on the millions whom they will affect; and we may reasonably infer that
among the motives which led Pitt to break with many of his friends not
the least was a heartfelt desire to safeguard the relations of the
feudatories to the Suzerain Power, and to protect the myriads of
Hindoos who had no protection save in the dimly known court of
appeal at Westminster.
On the charge respecting the spoliation of the Begums of Oude,
Pitt also cast his vote against Hastings; and again a majority followed
him. It is questionable whether even the sensationally brilliant oration
of Sheridan on this affecting topic moved the House so much as the
321
silent but scornful disapproval expressed in Pitt’s vote. The
impeachment was thenceforth inevitable.
With the forensic pageant that ensued we are not here concerned.
Thenceforth the case belonged strictly to the legal domain. Its duration
throughout the years 1788–95 was certainly discreditable to British
law. Hastings out of his never affluent fortunes spent some £71,000 in
322
the vindication of his actions, and at last secured an acquittal. But
though men in Europe forgot the case amidst the potent distractions of
the French Revolution, the effect of it was not lost upon the Orient. The
comparative calm which settled benignly on India for twelve years may
be attributed largely to a renewal of confidence in the sense of justice
of our people. After the events of the year 1786 princes and peasants
alike felt assured that the most transcendent services, if smirched with
acts of injustice, would never screen a Viceroy from the censure of the
British Parliament.
CHAPTER XI
THE IRISH PROBLEM
(1785)
[Secret.]
340
Sunday, February 20, 1785.
... I am able to tell you confidentially that we shall certainly
suspend the final approbation of the commercial system, and
declare the impossibility of completing it till more satisfaction and
explicit provision is made in Ireland respecting the object of
contribution.
Yours ever,
W. Pitt.