【文件属性】:
文件名称:programing C# edition5
文件大小:4.57MB
文件格式:PDF
更新时间:2012-05-09 12:39:31
C#
英文原版,清晰带目录。
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Part I. The C# Language
1. C# 3.0 and .NET 3.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Evolution of C# 3
The C# Language 4
The .NET Platform 6
2. Getting Started: “Hello World” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Classes, Objects, and Types 7
Developing “Hello World” 14
Using the Visual Studio 2008 Debugger 18
3. C# Language Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Types 21
Variables and Constants 25
Whitespace 33
Statements 33
Operators 49
Preprocessor Directives 59
4. Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Defining Classes 62
Creating Objects 67
Using Static Members 75
Destroying Objects 79
Passing Parameters 83
iv | Table of Contents
Overloading Methods and Constructors 89
Encapsulating Data with Properties 92
readonly Fields 96
5. Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Specialization and Generalization 98
Inheritance 101
Polymorphism 102
Abstract Classes 109
The Root of All Types: Object 113
Nesting Classes 115
6. Operator Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Using the operator Keyword 118
Supporting Other .NET Languages 119
Creating Useful Operators 120
Logical Pairs 120
The Equality Operator 120
Conversion Operators 121
Putting Operators to Work 121
7. Structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Defining Structs 128
Creating Structs 129
8. Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Defining and Implementing an Interface 132
Overriding Interface Implementations 147
Explicit Interface Implementation 151
9. Arrays, Indexers, and Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Arrays 156
The foreach Statement 162
Indexers 177
Collection Interfaces 186
Constraints 190
List 195
Queues 206
Stacks 208
Dictionaries 211
Table of Contents | v
10. Strings and Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Strings 215
Regular Expressions 229
11. Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Throwing and Catching Exceptions 242
Exception Objects 252
12. Delegates and Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Events 256
Events and Delegates 257
Anonymous Methods 271
Part II. C# and Data
13. Introducing LINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Defining and Executing a Query 280
LINQ and C# 285
Anonymous Types 291
Implicitly Typed Local Variables 291
Extension Methods 292
Lambda Expressions in LINQ 297
14. Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
XML Basics (A Quick Review) 302
X Stands for eXtensible 304
Creating XML Documents 304
Searching in XML with XPath 311
Searching Using XPathNavigator 322
XML Serialization 329
15. Putting LINQ to Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Getting Set Up 338
LINQ to SQL Fundamentals 339
Using Visual Studio LINQ to SQL Designer 344
Retrieving Data 349
Updating Data Using LINQ to SQL 353
Deleting Relational Data 358
LINQ to XML 363
vi | Table of Contents
16. ADO.NET and Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Relational Databases and SQL 368
The ADO.NET Object Model 372
Getting Started with ADO.NET 374
Part III. Programming with C#
17. Programming ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Web Forms Fundamentals 381
Creating a Web Form 385
Data Binding 391
18. Programming WPF Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
WPF in a Very Small Nutshell 404
Building the Application 406
What Have You Learned, Dorothy? 419
19. Programming Windows Forms Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Creating the Application 420
Part IV. The CLR and the .NET Framework
20. Attributes and Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Attributes 449
Reflection 456
21. Threads and Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Threads 466
Synchronization 474
Race Conditions and Deadlocks 485
22. Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Files and Directories 488
Reading and Writing Data 499
Asynchronous I/O 506
Network I/O 511
Web Streams 527
Serialization 529
Isolated Storage 538
Table of Contents | vii
23. Programming .NET and COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Importing ActiveX Controls 542
P/Invoke 551
Pointers 554
C# Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569