O''''Reilly - Programming C#

558 425 0
O''''Reilly - Programming C#

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Programming C# Jesse Liberty Publisher: O'Reilly First Edition July 2001 ISBN: 0-596-00117-7, 680 pages The goal of C# is to serve as a high-performance language for .NET development—one that is simple, safe, object-oriented, and Internet-centric. Programming C# teaches this new language in a way that experienced programmers will appreciate—by grounding its application firmly in the context of Microsoft's .NET platform and the development of desktop and Internet applications. 2 Programming C# 3 Preface 11 About This Book .11 How the Book Is Organized .11 Who This Book Is For .13 C# Versus Visual Basic .NET .13 C# Versus Java .14 C# versus C++ .14 Conventions Used in This Book 14 Support 15 We'd Like to Hear from You .15 Acknowledgements .16 Part I: The C# Language 17 Chapter 1. C# and the .NET Framework .17 1.1 The .NET Platform 17 1.2 The .NET Framework 17 1.3 Compilation and the MSIL 19 1.4 The C# Language .19 Chapter 2. Getting Started:"Hello World" .21 2.1 Classes, Objects, and Types 21 2.2 Developing "Hello World" 26 Just In Time Compilation 29 2.3 Using the Visual Studio .NET Debugger 29 Chapter 3. C# Language Fundamentals 33 3.1 Types 33 The Stack and the Heap .34 3.2 Variables and Constants 36 WriteLine( ) 36 3.3 Expressions 42 3.4 Whitespace .42 3.5 Statements .43 Statement Blocks .46 All Operators Are Not Created Equal 47 Whitespace and Braces 53 3.6 Operators 56 Short-Circuit Evaluation 61 3.7 Namespaces .63 3.8 Preprocessor Directives .65 Chapter 4. Classes and Objects 69 4.1 Defining Classes .69 4.2 Creating Objects .73 4.3 Using Static Members .78 Static Methods to Access Static Fields 82 4.4 Destroying Objects 82 How Finalize Works .82 4.5 Passing Parameters .84 4.6 Overloading Methods and Constructors 89 4 4.7 Encapsulating Data with Properties 91 4.8 Readonly Fields .94 Chapter 5. Inheritance and Polymorphism 97 5.1 Specialization and Generalization 97 About the Unified Modeling Language .97 5.2 Inheritance .99 5.3 Polymorphism 102 5.4 Abstract Classes .107 5.5 The Root of all Classes: Object 110 5.6 Boxing and Unboxing Types 112 5.7 Nesting Classes .114 Chapter 6. Operator Overloading 117 6.1 Using the operator Keyword 117 6.2 Supporting Other .NET Languages 118 6.3 Creating Useful Operators 118 6.4 Logical Pairs .118 6.5 The Equals Operator .118 6.6 Conversion Operators .119 Chapter 7. Structs 125 7.1 Defining Structs 125 7.2 Creating Structs 127 Chapter 8. Interfaces .131 Mix Ins .131 8.1 Implementing an Interface 131 8.2 Accessing Interface Methods .141 8.3 Overriding Interface Implementations 147 8.4 Explicit Interface Implementation .150 Chapter 9. Arrays, Indexers, and Collections 159 9.1 Arrays .159 9.2 The foreach Statement 162 9.3 Indexers .175 9.4 Collection Interfaces .182 9.5 Array Lists .187 9.6 Queues .197 9.7 Stacks .199 9.8 Dictionaries .202 Load Factor .204 Chapter 10. Strings and Regular Expressions 209 10.1 Strings .209 Delimiter Limitations 222 10.2 Regular Expressions .222 Chapter 11. Handling Exceptions 233 11.1 Throwing and Catching Exceptions 233 11.2 Exception Objects 241 11.3 Custom Exceptions .244 11.4 Rethrowing Exceptions 246 Chapter 12. Delegates and Events .251 12.1 Delegates 251 Programming C# 5 12.2 Events 268 Part II: Programming with C# .277 Chapter 13. Building Windows Applications 277 13.1 Creating a Simple Windows Form .278 13.2 Creating a Windows Form Application 289 13.3 XML Documentation Comments 309 13.4 Deploying an Application 311 Chapter 14. Accessing Data with ADO.NET .321 14.1 Relational Databases and SQL .321 14.2 The ADO.Net Object Model 324 14.3 Getting Started with ADO.NET .325 14.4 Using ADO Managed Providers .328 14.5 Working with Data-Bound Controls 330 14.6 Changing Database Records .340 14.7 ADO.NET and XML .353 Chapter 15. ProgrammingWeb Applications with Web Forms .355 15.1 Understanding Web Forms 355 15.2 Creating a Web Form .358 15.3 Adding Controls 361 15.4 Data Binding 362 15.5 Responding to Postback Events .369 15.6 ASP.NET and C# 371 Chapter 16. Programming Web Services 373 16.1 SOAP, WSDL, and Discovery .373 16.2 Building a Web Service .374 WSDL and Namespaces 375 16.3 Creating the Proxy 379 Part III: C# and the .NET CLR .385 Chapter 17. Assemblies and Versioning 385 17.1 PE Files 385 17.2 Metadata .385 17.3 Security Boundary .385 17.4 Versioning .385 17.5 Manifests .386 17.6 Multi-Module Assemblies 387 17.7 Private Assemblies 395 17.8 Shared Assemblies 395 Public Key Encryption .397 Chapter 18. Attributes and Reflection .401 18.1 Attributes 401 18.2 Intrinsic Attributes 401 18.3 Custom Attributes .403 18.4 Reflection 407 18.5 Reflection Emit .416 Chapter 19. Marshaling and Remoting .437 19.1 Application Domains .438 19.2 Context 446 19.3 Remoting .448 6 Chapter 20. Threads and Synchronization 457 20.1 Threads 457 20.2 Synchronization 465 20.3 Race Conditions and Deadlocks .474 Chapter 21. Streams .477 21.1 Files and Directories .477 21.2 Reading and Writing Data 487 21.3 Asynchronous I/O 493 21.4 Network I/O .497 21.5 Web Streams .513 21.6 Serialization .516 21.7 Isolated Storage 523 Chapter 22. Programming .NET and COM 527 22.1 Importing ActiveX Controls .527 22.2 Importing COM Components .534 22.3 Exporting .NET Components .541 22.4 P/Invoke 543 22.5 Pointers .545 Appendix A. C# Keywords 551 Colophon .558 Programming C# 7 Programming C# Preface About This Book How the Book Is Organized Who This Book Is For C# Versus Visual Basic .NET C# Versus Java C# versus C++ Conventions Used in This Book Support We'd Like to Hear from You Acknowledgements I: The C# Language 1. C# and the .NET Framework 1.1 The .NET Platform 1.2 The .NET Framework 1.3 Compilation and the MSIL 1.4 The C# Language 2. Getting Started:"Hello World" 2.1 Classes, Objects, and Types 2.2 Developing "Hello World" 2.3 Using the Visual Studio .NET Debugger 3. C# Language Fundamentals 3.1 Types 3.2 Variables and Constants 3.3 Expressions 3.4 Whitespace 3.5 Statements 3.6 Operators 3.7 Namespaces 3.8 Preprocessor Directives 4. Classes and Objects 4.1 Defining Classes 4.2 Creating Objects 4.3 Using Static Members 4.4 Destroying Objects 4.5 Passing Parameters 4.6 Overloading Methods and Constructors 4.7 Encapsulating Data with Properties 4.8 Readonly Fields 5. Inheritance and Polymorphism 5.1 Specialization and Generalization 5.2 Inheritance 8 5.3 Polymorphism 5.4 Abstract Classes 5.5 The Root of all Classes: Object 5.6 Boxing and Unboxing Types 5.7 Nesting Classes 6. Operator Overloading 6.1 Using the operator Keyword 6.2 Supporting Other .NET Languages 6.3 Creating Useful Operators 6.4 Logical Pairs 6.5 The Equals Operator 6.6 Conversion Operators 7. Structs 7.1 Defining Structs 7.2 Creating Structs 8. Interfaces 8.1 Implementing an Interface 8.2 Accessing Interface Methods 8.3 Overriding Interface Implementations 8.4 Explicit Interface Implementation 9. Arrays, Indexers, and Collections 9.1 Arrays 9.2 The foreach Statement 9.3 Indexers 9.4 Collection Interfaces 9.5 Array Lists 9.6 Queues 9.7 Stacks 9.8 Dictionaries 10. Strings and Regular Expressions 10.1 Strings 10.2 Regular Expressions 11. Handling Exceptions 11.1 Throwing and Catching Exceptions 11.2 Exception Objects 11.3 Custom Exceptions 11.4 Rethrowing Exceptions 12. Delegates and Events 12.1 Delegates 12.2 Events II: Programming with C# Programming C# 9 13. Building Windows Applications 13.1 Creating a Simple Windows Form 13.2 Creating a Windows Form Application 13.3 XML Documentation Comments 13.4 Deploying an Application 14. Accessing Data with ADO.NET 14.1 Relational Databases and SQL 14.2 The ADO.Net Object Model 14.3 Getting Started with ADO.NET 14.4 Using ADO Managed Providers 14.5 Working with Data-Bound Controls 14.6 Changing Database Records 14.7 ADO.NET and XML 15. ProgrammingWeb Applications with Web Forms 15.1 Understanding Web Forms 15.2 Creating a Web Form 15.3 Adding Controls 15.4 Data Binding 15.5 Responding to Postback Events 15.6 ASP.NET and C# 16. Programming Web Services 16.1 SOAP, WSDL, and Discovery 16.2 Building a Web Service 16.3 Creating the Proxy III: C# and the .NET CLR 17. Assemblies and Versioning 17.1 PE Files 17.2 Metadata 17.3 Security Boundary 17.4 Versioning 17.5 Manifests 17.6 Multi-Module Assemblies 17.7 Private Assemblies 17.8 Shared Assemblies 18. Attributes and Reflection 18.1 Attributes 18.2 Intrinsic Attributes 18.3 Custom Attributes 18.4 Reflection 18.5 Reflection Emit 19. Marshaling and Remoting 19.1 Application Domains 19.2 Context 10 19.3 Remoting 20. Threads and Synchronization 20.1 Threads 20.2 Synchronization 20.3 Race Conditions and Deadlocks 21. Streams 21.1 Files and Directories 21.2 Reading and Writing Data 21.3 Asynchronous I/O 21.4 Network I/O 21.5 Web Streams 21.6 Serialization 21.7 Isolated Storage 22. Programming .NET and COM 22.1 Importing ActiveX Controls 22.2 Importing COM Components 22.3 Exporting .NET Components 22.4 P/Invoke 22.5 Pointers A. C# Keywords Colophon [...]... from it in C# 1.4 The C# Language The C# language is disarmingly simple, with only about 80 keywords and a dozen built-in datatypes, but C# is highly expressive when it comes to implementing modern programming concepts C# includes all the support for structured, component-based, object-oriented programming that one expects of a modern language built on the shoulders of C++ and Java The C# language... values between -2 ,147,483,647 and 2,147,483,647 Unsigned integer values between 0 and 4,294,967,295 Floating point number Holds the values from approximately + /-1 .5 * Single -4 5 38 10 to approximate + /-3 .4 * 10 with 7 significant figures Double-precision floating point; holds the values from approximately Double + /-5 .0 * 1 0-3 24 to approximate + /-1 .7 * 10308 with 1 5-1 6 significant figures Fixed-precision... the C# primitive types to the underlying NET type ensures that objects created in C# can be used interchangeably with objects created in any other language compliant with the NET CLS, such as VB NET 33 Each type has a specific and unchanging size Unlike with C++, a C# int is always 4 bytes because it maps to an Int32 in the NET CLS Table 3-1 lists the built-in value types offered by C# Table 3-1 C#. .. manuscript and saved me from a series of embarrassing errors and omissions I am deeply grateful 16 Programming C# Part I: The C# Language Chapter 1 C# and the NET Framework The goal of C# is to provide a simple, safe, modern, object-oriented, Internet-centric, highperformance language for NET development C# is a new language, but it draws on the lessons learned over the past three decades In much the... NET represents a major change in the way you'll think about programming It is, in short, a new development platform designed to facilitate object-oriented Internet development The programming language of choice for this object-oriented Internet-centric platform is C# which builds on the lessons learned from C (high performance), C++ (object-oriented structure), Java (security), and Visual Basic (rapid... interface Chapter 11, explains how to deal with exceptions, which provide an object-oriented mechanism for handling life's little emergencies Both Windows and web applications are event-driven In C#, events are first-class members of the language Chapter 12, focuses on how events are managed, and how delegates, object-oriented type-safe callback mechanisms, are used to support event handling Part II This section... pillars of object-oriented programming In C# everything pertaining to a class declaration is found in the declaration itself C# class definitions do not require separate header files or Interface Definition Language (IDL) files Moreover, C# supports a new XML style of inline documentation that greatly simplifies the creation of online and print reference documentation for an application C# also supports... program In this chapter, we will create, compile, and run a simple "Hello World" program written in C# The analysis of this brief program will introduce key features of the C# language Example 2-1 illustrates the fundamental elements of a very elementary C# program Example 2-1 A simple "Hello World" program in C# class HelloWorld { static void Main( ) { // Use the system console object System.Console.WriteLine("Hello... (if you are using Visual Studio for the first time, the New Project window might appear without further prompting) Figure 2-1 shows the New Project window Figure 2-1 Creating a C# console application in Visual Studio NET 26 Programming C# To open your application, select Visual C# Projects in the Project Type window and select Console Application in the Template window You can now enter a name for the... "Hello World" program using the C# command-line compiler: 1 Save Example 2-1 as the file hello.cs 2 Open a command window (Start->Run and type in cmd) 3 From the command line, enter: csc hello.cs This step will build the executable (EXE) file If the program contains errors, the compiler will report them in the command window 4 To run the program, enter: 28 Programming C# Hello You should see the venerable . Programming C# Jesse Liberty Publisher: O'Reilly First Edition July 2001 ISBN: 0-5 9 6-0 011 7-7 , 680 pages The goal of C# is to serve as a high-performance. Colophon .558 Programming C# 7 Programming C# Preface About This Book How the Book Is Organized Who This Book Is For C# Versus Visual Basic .NET C# Versus Java C#

Ngày đăng: 04/11/2013, 13:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan