logo资料库

C#6.0本质论(英文版)全.pdf

第1页 / 共1046页
第2页 / 共1046页
第3页 / 共1046页
第4页 / 共1046页
第5页 / 共1046页
第6页 / 共1046页
第7页 / 共1046页
第8页 / 共1046页
资料共1046页,剩余部分请下载后查看
Contents
Figures
Tables
Foreword
Preface
Acknowledgments
About the Authors
1 Introducing C#
Hello, World
C# Syntax Fundamentals
Console Input and Output
2 Data Types
Fundamental Numeric Types
More Fundamental Types
null and void
Categories of Types
Nullable Modifier
Conversions between Data Types
Arrays
3 Operators and Control Flow
Operators
Introducing Flow Control
Code Blocks ({})
Code Blocks, Scopes, and Declaration Spaces
Boolean Expressions
Bitwise Operators (<<, >>, |, &, ^, ~)
Control Flow Statements, Continued
Jump Statements
C# Preprocessor Directives
4 Methods and Parameters
Calling a Method
Declaring a Method
The using Directive
Returns and Parameters on Main()
Advanced Method Parameters
Recursion
Method Overloading
Optional Parameters
Basic Error Handling with Exceptions
5 Classes
Declaring and Instantiating a Class
Instance Fields
Instance Methods
Using the this Keyword
Access Modifiers
Properties
Constructors
Static Members
Extension Methods
Encapsulating the Data
Nested Classes
Partial Classes
6 Inheritance
Derivation
Overriding the Base Class
Abstract Classes
All Classes Derive from System.Object
Verifying the Underlying Type with the is Operator
Conversion Using the as Operator
7 Interfaces
Introducing Interfaces
Polymorphism through Interfaces
Interface Implementation
Converting between the Implementing Class and Its Interfaces
Interface Inheritance
Multiple Interface Inheritance
Extension Methods on Interfaces
Implementing Multiple Inheritance via Interfaces
Versioning
Interfaces Compared with Classes
Interfaces Compared with Attributes
8 Value Types
Structs
Boxing
Enums
9 Well-Formed Types
Overriding object Members
Operator Overloading
Referencing Other Assemblies
Defining Namespaces
XML Comments
Garbage Collection
Resource Cleanup
Lazy Initialization
10 Exception Handling
Multiple Exception Types
Catching Exceptions
General Catch Block
Guidelines for Exception Handling
Defining Custom Exceptions
Rethrowing a Wrapped Exception
11 Generics
C# without Generics
Introducing Generic Types
Constraints
Generic Methods
Covariance and Contravariance
Generic Internals
12 Delegates and Lambda Expressions
Introducing Delegates
Lambda Expressions
Anonymous Methods
General-Purpose Delegates: System.Func and System.Action
13 Events
Coding the Observer Pattern with Multicast Delegates
Events
14 Collection Interfaces with Standard Query Operators
Anonymous Types and Implicitly Typed Local Variables
Collection Initializers
What Makes a Class a Collection: IEnumerable
Standard Query Operators
15 LINQ with Query Expressions
Introducing Query Expressions
Query Expressions Are Just Method Invocations
16 Building Custom Collections
More Collection Interfaces
Primary Collection Classes
Providing an Indexer
Returning Null or an Empty Collection
Iterators
17 Reflection, Attributes, and Dynamic Programming
Reflection
nameof Operator
Attributes
Programming with Dynamic Objects
18 Multithreading
Multithreading Basics
Working with System.Threading
Asynchronous Tasks
Canceling a Task
The Task-Based Asynchronous Pattern
Executing Loop Iterations in Parallel
Running LINQ Queries in Parallel
19 Thread Synchronization
Why Synchronization?
Timers
20 Platform Interoperability and Unsafe Code
Platform Invoke
Pointers and Addresses
Executing Unsafe Code via a Delegate
Using the Windows Runtime Libraries from C#
21 The Common Language Infrastructure
Defining the Common Language Infrastructure
CLI Implementations
C# Compilation to Machine Code
Runtime
Application Domains
Assemblies, Manifests, and Modules
Common Intermediate Language
Common Type System
Common Language Specification
Base Class Library
Metadata
A: Downloading and Installing the C# Compiler and CLI Platform
Microsoft’s .NET
B: Tic-Tac-Toe Source Code Listing
C: Interfacing with Multithreading Patterns prior to the TPL and C# 6.0
D: Timers Prior to the Async/Await Pattern of C# 5.0
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Index of 6.0 Topics
A
B
C
D
E
I
M
N
O
P
R
S
T
U
V
W
Index of 5.0 Topics
A
B
C
D
E
G
H
I
L
M
N
O
P
R
S
T
U
W
Index of 4.0 Topics
A
B
C
D
E
F
G
H
I
L
M
N
O
P
R
S
T
U
W
Index of 3.0 Topics
A
B
C
D
E
F
G
I
J
L
M
N
O
P
Q
R
S
T
U
V
W
ptg16606403
Essential C# 6.0
The Addison-Wesley Microsoft Technology Series Visit informit.com/mstechseries for a complete list of available products. Titles in The Addison-Wesley Microsoft Technology Series address the latest Microsoft technologies used by developers, IT professionals, managers, and architects. Titles in this series cover a broad range of topics, from programming languages to servers to advanced developer techniques. The books are written by thought leaders and experts in their respective communities, including many MVPs and RDs. The format of this series was created with ease-of-use in mind, incorporating features that make finding topics simple; visually friendly charts and fonts; and thorough and intuitive indexes. With trusted authors, rigorous technical reviews, authoritative coverage, and independent viewpoints, the Microsoft Community can rely on Addison-Wesley to deliver the highest quality technical information. Make sure to connect with us! informit.com/socialconnect ptg16606403
Essential C# 6.0 Mark Michaelis with Eric Lippert New York • Boston • Indianapolis • San Francisco Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City ptg16606403
Microsoft, Windows, Visual Basic, Visual C#, and Visual C++ are either registered trademarks or trade- marks of Microsoft Corporation in the U.S.A. and/or other countries/regions. 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 the publisher was aware of a trade- mark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corp- sales@pearsoned.com or (800) 382-3419. For government sales inquiries, please contact governmentsales@pearsoned.com. For questions about sales outside the U.S., please contact international@pearsoned.com. Visit us on the Web: informit.com/aw Library of Congress Cataloging-in-Publication Data Michaelis, Mark. Essential C# 6.0 / Mark Michaelis with Eric Lippert. pages cm Includes index. ISBN 978-0-13-414104-6 (pbk. : alk. paper) — ISBN 0-13-414104-0 (pbk. : alk. paper) 1. C# (Computer program language) 2. Microsoft .NET Framework. I. Lippert, Eric, author. II. Title. QA76.73.C154M5239 2016 005.13’3—dc23 2015025757 Copyright © 2016 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a re- trieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, record- ing, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 200 Old Tappan Road, Old Tappan, New Jersey 07657, or you may fax your request to (201) 236-3290. ISBN-13: 978-0-13-414104-6 ISBN-10: 0-13-414104-0 Text printed in the United States on recycled paper at Edwards Brothers Malloy in Ann Arbor, Michigan First printing, September 2015 ptg16606403
To my family: Elisabeth, Benjamin, Hanna, and Abigail. You have sacrificed a husband and daddy for countless hours of writing, frequently at times when he was needed most. Thanks! n ptg16606403
This page intentionally left blank ptg16606403
Contents at a Glance Figures xv Contents ix Tables xvii Foreword xix Preface xxiii Acknowledgments xxxv About the Authors xxxvii 1 Introducing C# 1 2 Data Types 35 3 Operators and Control Flow 89 4 Methods and Parameters 161 5 Classes 217 6 Inheritance 289 7 Interfaces 325 8 Value Types 351 9 Well-Formed Types 383 10 Exception Handling 433 11 Generics 455 12 Delegates and Lambda Expressions 505 vii ptg16606403
分享到:
收藏