(Ebook) Programming C# 5.0: Building Windows 8, Web, and Desktop Applications for the .NET 4.5 Framework by Ian Griffiths ISBN 9781449320416, 1449320414 download
(Ebook) Programming C# 5.0: Building Windows 8, Web, and Desktop Applications for the .NET 4.5 Framework by Ian Griffiths ISBN 9781449320416, 1449320414 download
0: Building Windows 8,
Web, and Desktop Applications for the .NET 4.5
Framework by Ian Griffiths ISBN 9781449320416,
1449320414 download
https://ebooknice.com/product/programming-c-5-0-building-
windows-8-web-and-desktop-applications-for-the-
net-4-5-framework-4577356
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
https://ebooknice.com/product/programming-c-8-0-build-cloud-web-and-
desktop-applications-10609654
https://ebooknice.com/product/programming-c-12-build-cloud-web-and-desktop-
applications-57762818
(Ebook) Programming C# 12.0 Build Cloud, Web, and Desktop
Applications (Early Release) by Ian Griffiths ISBN
9781098158354, 1098158350
https://ebooknice.com/product/programming-c-12-0-build-cloud-web-and-
desktop-applications-early-release-52792294
https://ebooknice.com/product/programming-c-10-build-cloud-web-and-desktop-
applications-final-early-release-43862872
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312
https://ebooknice.com/product/sat-ii-success-math-1c-and-2c-2002-peterson-
s-sat-ii-success-1722018
https://ebooknice.com/product/programming-wpf-building-windows-ui-with-
windows-presentation-foundation-982350
Programming C# 5.0
Ian Griffiths
Programming C# 5.0
by Ian Griffiths
Copyright © 2013 Ian Griffiths. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or [email protected].
Editor: Rachel Roumeliotis Proofreader: Linley Dolby
Production Editor: Kristen Borg Indexer: Ellen Troutman
Copyeditor: Rachel Monaghan Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Rebecca Demarest
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc. Programming C# 5.0, the image of an African crowned crane, and related trade dress are trade
marks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade
mark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-32041-6
[LSI]
I dedicate this book to my excellent wife Deborah, and to my wonderful daughter, Hazel,
who arrived while this book was a work in progress.
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
1. Introducing C#. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Why C#? 1
Why Not C#? 3
C#’s Defining Features 5
Managed Code and the CLR 7
Generality Trumps Specialization 9
Asynchronous Programming 10
Visual Studio 10
Anatomy of a Simple Program 13
Adding a Project to an Existing Solution 15
Referencing One Project from Another 15
Writing a Unit Test 17
Namespaces 20
Classes 24
Program Entry Point 25
Unit Tests 26
Summary 27
v
#line 50
#pragma 50
#region and #endregion 51
Intrinsic Data Types 51
Numeric Types 52
Booleans 61
Strings and Characters 62
Object 62
Operators 62
Flow Control 68
Boolean Decisions with if Statements 68
Multiple Choice with switch Statements 70
Loops: while and do 72
C-Style for Loops 73
Collection Iteration with foreach Loops 75
Summary 76
3. Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Classes 77
Static Members 80
Static Classes 82
Reference Types 83
Structs 89
When to Write a Value Type 93
Members 98
Fields 98
Constructors 100
Methods 108
Properties 114
Indexers 117
Operators 119
Events 122
Nested Types 122
Interfaces 124
Enums 126
Other Types 129
Anonymous Types 129
Partial Types and Methods 130
Summary 131
4. Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Generic Types 134
vi | Table of Contents
Constraints 136
Type Constraints 137
Reference Type Constraints 139
Value Type Constraints 142
Multiple Constraints 142
Zero-Like Values 143
Generic Methods 144
Type Inference 145
Inside Generics 145
Summary 147
5. Collections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Arrays 149
Array Initialization 153
Variable Argument Count with the params Keyword 154
Searching and Sorting 155
Multidimensional Arrays 162
Copying and Resizing 166
List<T> 167
List and Sequence Interfaces 170
Implementing Lists and Sequences 174
Iterators 175
Collection<T> 179
ReadOnlyCollection<T> 180
Dictionaries 181
Sorted Dictionaries 184
Sets 185
Queues and Stacks 186
Linked Lists 187
Concurrent Collections 188
Tuples 189
Summary 190
6. Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Inheritance and Conversions 192
Interface Inheritance 194
Generics 195
Covariance and Contravariance 196
System.Object 202
The Ubiquitous Methods of object 202
Accessibility and Inheritance 203
Virtual Methods 204
8. Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Exception Sources 267
Exceptions from APIs 268
Exceptions from Your Code 270
Failures Detected by the Runtime 271
Handling Exceptions 272
Exception Objects 273
Multiple catch Blocks 274
Nested try Blocks 275
finally Blocks 277
Throwing Exceptions 278
Rethrowing Exceptions 279
Failing Fast 282
Exception Types 283
Custom Exceptions 285
Unhandled Exceptions 288
Debugging and Exceptions 290
Asynchronous Exceptions 292
Table of Contents | ix
Entity Framework 387
LINQ to SQL 387
WCF Data Services Client 388
Parallel LINQ (PLINQ) 388
LINQ to XML 388
Reactive Extensions 388
Summary 389
x | Table of Contents
ReplaySubject<T> 440
AsyncSubject<T> 441
Adaptation 441
IEnumerable<T> 441
.NET Events 443
Asynchronous APIs 445
Timed Operations 447
Interval 447
Timer 449
Timestamp 449
TimeInterval 450
Throttle 451
Sample 451
Timeout 451
Windowing Operators 451
Delay 452
DelaySubscription 453
Summary 453
Table of Contents | xi
Summary 486
Table of Contents | xv
MVC 759
Typical MVC Project Layout 759
Writing Models 766
Writing Views 768
Writing Controllers 770
Handling Additional Input 772
Generating Action Links 775
Routing 775
Summary 780
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821
C# is now well into its second decade. It has grown steadily in both power and size, but
Microsoft has always kept the essential characteristics intact—C# still feels like the same
language as was first unveiled back in 2000. Each new capability is designed to integrate
cleanly with the rest, enhancing the language without turning it into an incoherent bag
of miscellaneous features. This philosophy is evident in the most important new addi
tion to C#—its support for asynchronous programming. It has always been possible to
use asynchronous APIs in C#, but in the past, this tended to involve convoluted code.
In C# 5.0, you can write asynchronous code that looks almost exactly like normal code,
so instead of adding weight to the language, this new asynchronous programming sup
port makes things simpler.
Even though C# continues to be a fairly straightforward language at its heart, there is a
great deal more to say about it now than in its first incarnation. Successive editions of
this book have responded to the language’s progress with ever-increasing page counts,
but this latest edition does not merely try to cram in yet more details. It expects a some
what higher level of technical ability from its readers than before.
xvii
presents these common ideas, but the focus is on the details specific to C#, rather than
the broad concepts. So if you have read previous editions of this book, you will find that
this one spends less time on these basic concepts, and goes into rather more detail on
everything else.
xviii | Preface
Random documents with unrelated
content Scribd suggests to you:
Neotropical Nearctic Palæarctic Ethiopian Oriental Australian
Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions.
——— 1. 2. 3. 1. 2. 3. ——— 1. 2. 3. 1. 2 — 4
— 4 4 — 4
Sitta (17 sp.), Palæarctic and Nearctic regions to South India and
Mexico; Dendrophila (2 sp.), Ceylon and India to Burmah and
Malaya; Hypherpes (1 sp.), Madagascar; Sittella (6 sp.), Australia and
New Guinea. Acanthisitta (1 sp.) and Xenicus (4 sp.), New Zealand,
are placed with some doubt in this family.
General Distribution.
——3 1. 2. 3. 1. 2. 3. 1. 2. 3 1. 2. 3. —2—4
— 4 4 — 4
The Paridæ, or Tits, are very abundant in the Nearctic and Palæarctic
regions; many fine species are found in the Himalayas, but they are
sparingly scattered through the Ethiopian, Oriental, and Australian
regions. The genera usually admitted into this family are the
following, but the position of some of them, especially of the
Australian forms, is doubtful.
General Distribution.
General Distribution.
(1022) Phyllornis (12 sp.), India to Java, Ceylon, and Hainan; (1166)
Iora (4 sp.), the whole Oriental region; (1163) Erpornis (2 sp.),
Borneo, Himalayas, Hainan, and Formosa.
General Distribution.
Neotropical Nearctic Palæarctic Ethiopian Oriental Australian
Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions.
General Distribution.
Oriolus (24 sp.), Central Europe, throughout Africa, and the whole
Oriental region, northward to Pekin, and eastward to Flores; (1073)
Analcipus (3 sp.), Himalayas, Formosa, Java and Borneo; Mimeta (9
sp.), the Moluccas and Australia; Sphecotheres (3 sp.), Timor and
Australia. Artamia (1 sp.), Madagascar,—perhaps belongs to the next
family or to Laniidæ.
General Distribution.
General Distribution.
General Distribution.
——— ——— 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3.
— — 4 4 4 4
General Distribution.
Neotropical Nearctic Palæarctic Ethiopian Oriental Australian
Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions.
General Distribution.
——— 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3
— 4 4 4 4 —
The Laniidæ, or Shrikes (Laniinæ and Malaconotinæ of the Hand List,
and including Colluricincla), are most abundant and varied in Africa,
less plentiful in the Oriental, Australian, and Palæarctic regions, with
a few species in the Nearctic region as far as Mexico. The
constitution of the family is, however, somewhat uncertain. The
genera here admitted are:—
General Distribution.
1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3
4 4 4 4 4 —
The Corvidæ, or Crows, Jays, &c., form an extensive and somewhat
heterogeneous group, some members of which inhabit almost every
part of the globe, although none of the genera are cosmopolitan.
The true crows are found everywhere but in South America; the
magpies, choughs, and nutcrackers are characteristic of the
Palæarctic region; the jays are Palæarctic, Oriental, and American;
while the piping crows are peculiarly Australian. The more detailed
distribution of the genera is as follows:—
General Distribution.
General Distribution.
Neotropical Nearctic Palæarctic Ethiopian Oriental Australian
Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions. Sub-regions.
(As in the Hand List, but omitting Zosterops, and slightly altering
the arrangement.)
Myzomela (18 sp.), has the widest range, extending from Celebes to
the Samoa Islands, and to Timor and Eastern Australia; Entomophila
(4 sp.), Australia and New Guinea; Gliciphila (10 sp.), Australia,
Timor, New Guinea, and New Caledonia; Acanthorhynchus (2 sp.),
Australia and Tasmania; Meliphaga (1 sp.), Australia; Ptilotis (40 sp.),
Gilolo and Lombok to Australia and Tasmania, and to the Samoa and
Tonga Islands; Meliornis (5 sp.), Australia and Tasmania;
Prosthemadera (1 sp.), Pogonornis (1 sp.), New Zealand; Anthornis
(4 sp.), New Zealand and Chatham Islands; Anthochæra (4 sp.),
Australia and Tasmania; Xanthotis (4 sp.), Papuan Islands and
Australia; Leptornis (2 sp.), Samoa Islands and New Caledonia;
Philemon = Tropidorhyncus (18 sp.), Moluccas and Lombok to New
Guinea, Australia, Tasmania and New Caledonia; Entomiza (2 sp.),
Australia; Manorhina (5 sp.), Australia and Tasmania; Euthyrhynchus
(3 sp.), New Guinea; Melirrhophetes (2 sp.), New Guinea; Melidectes
(1 sp.), New Guinea; Melipotes (1 sp.), New Guinea; Melithreptus (8
sp.), New Guinea, Australia, and Tasmania; (397) Moho (3 sp.),
Sandwich Islands; Chætoptila (1 sp.), Sandwich Islands.
Family 23.—NECTARINIIDÆ. (11 Genera, 122 Species.)
General Distribution.
General Distribution.
General Distribution.
General Distribution.
General Distribution.
(918) Siurus (4 sp.), Venezuela and West Indies to Eastern States and
Canada; Mniotilta (1 sp.), Venezuela, Mexico, and Antilles to the
Eastern States; Parula (5 sp.), Brazil to Mexico, and the Eastern
States, and Canada; Protonotaria (1 sp.), Antilles to Ohio;
Helminthophaga (8 sp.), Columbia to Arctic America; Helmintherus (2
sp.), Central America to Eastern States; Perissoglossa (1 sp.), Antilles
and Eastern States; Dendrœca (33 sp.), Amazon to Antilles, and
Arctic America, and south to Chili; Oporornis (2 sp.), Guatemala to
Eastern States; Geothlypis (11 sp.), all North America and Brazil;
Myiodioctes (5 sp.), all North America and Columbia; Basileuterus (22
sp.), Bolivia and Brazil to Mexico; Setophaga (15 sp.), Brazil to
Canada; Ergaticus (2 sp.), Guatemala and Mexico; Cardellina (1 sp.),
Guatemala and Mexico; (1440) Granatellus (3 sp.), Amazon to
Mexico; (1441) Teretristis (2 sp.), Cuba; (1439) Icteria (2 sp.), Costa
Rica and United States to Canada.
General Distribution.
General Distribution.
General Distribution.
1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3.
4 4 4 4 4 4
(215—221 226—228) Hirundo (40 sp.), the range of the entire family;
(222 223) Psalidoprogne (10 sp.), Tropical and South Africa; (224)
Phedina (1 sp.), Madagascar and Mascarene Islands; (225)
Petrochelidon (5 sp.), North and South America and Cape of Good
Hope; (220—232 ?234) Atticora (8 sp.), the Neotropical region and ?
Australia; (235 237) Cotyle (11 sp.), Europe, India, Africa, North
America, Antilles and Ecuador; (236) Stelgidopteryx (5 sp.), La Plata
to United States; (238 and 239) Chelidon (6 sp.), Palæarctic region,
Nepal, Borneo; (240—242) Progne (5 sp.), all North and South
America.
General Distribution.
General Distribution.
General Distribution.
1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. ———
4 4 4 4 4 —
General Distribution.
and Java to Australia; (1688 1690 1691 1695 1696) Pytelia (24 sp.),
Tropical and South Africa; (1694) Hypargos (2 sp.), Mozambique and
Madagascar; (1697) Emblema (1 sp.), North-west Australia (1699 1712
—1717) Amadina (15 sp.), Tropical and South Africa, Moluccas to
Australia and the Samoa Islands; (1700 1701 1710) Spermestes (8 sp.),
Tropical Africa and Madagascar; (1702) Amauresthes (1 sp.), East and
West Africa; (1703 1707—1709 1711) Munia (30 sp.), Oriental region to
Timor and New Guinea; (1704) Donacola (3 sp.), Australia; (1705 1706)
Poephila (6 sp.), Australia; (1718—1721) Erythrura (7 sp.), Sumatra to
Java, Moluccas, Timor, New Guinea, and Fiji Islands; (1722)
Hypochera (3 sp.), Tropical and South Africa.
General Distribution.
——— ——— 1. 2. 3. 1. 2. 3. 1. 2. 3. 1 — 3. 4
— — 4 4 4
General Distribution.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com