apostila c# iniciando

apostila c# iniciando

(Parte 1 de 11)

Programming C#

Jesse Liberty

Publisher: O'Reilly

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.

Programming C#

Preface1
About This Book1
How the Book Is Organized1
Who This Book Is For13
C# Versus Visual Basic .NET13
C# Versus Java14
C# versus C++14
Conventions Used in This Book14
Support15
We'd Like to Hear from You15
Acknowledgements16
Part I: The C# Language17
Chapter 1. C# and the .NET Framework17
1.1 The .NET Platform17
1.2 The .NET Framework17
1.3 Compilation and the MSIL19
1.4 The C# Language19
Chapter 2. Getting Started:"Hello World"21
2.1 Classes, Objects, and Types21
2.2 Developing "Hello World"26
Just In Time Compilation29
2.3 Using the Visual Studio .NET Debugger29
Chapter 3. C# Language Fundamentals3
3.1 Types3
The Stack and the Heap34
3.2 Variables and Constants36
WriteLine( )36
3.3 Expressions42
3.4 Whitespace42
3.5 Statements43
Statement Blocks46
All Operators Are Not Created Equal47
Whitespace and Braces53
3.6 Operators56
Short-Circuit Evaluation61
3.7 Namespaces63
3.8 Preprocessor Directives65
Chapter 4. Classes and Objects69
4.1 Defining Classes69
4.2 Creating Objects73
4.3 Using Static Members78
Static Methods to Access Static Fields82
4.4 Destroying Objects82
How Finalize Works82
4.5 Passing Parameters84
4.7 Encapsulating Data with Properties91
4.8 Readonly Fields94
Chapter 5. Inheritance and Polymorphism97
5.1 Specialization and Generalization97
About the Unified Modeling Language97
5.2 Inheritance9
5.3 Polymorphism102
5.4 Abstract Classes107
5.5 The Root of all Classes: Object110
5.6 Boxing and Unboxing Types112
5.7 Nesting Classes114
Chapter 6. Operator Overloading117
6.1 Using the operator Keyword117
6.2 Supporting Other .NET Languages118
6.3 Creating Useful Operators118
6.4 Logical Pairs118
6.5 The Equals Operator118
6.6 Conversion Operators119
Chapter 7. Structs125
7.1 Defining Structs125
7.2 Creating Structs127
Chapter 8. Interfaces131
Mix Ins131
8.1 Implementing an Interface131
8.2 Accessing Interface Methods141
8.3 Overriding Interface Implementations147
8.4 Explicit Interface Implementation150
Chapter 9. Arrays, Indexers, and Collections159
9.1 Arrays159
9.2 The foreach Statement162
9.3 Indexers175
9.4 Collection Interfaces182
9.5 Array Lists187
9.6 Queues197
9.7 Stacks199
9.8 Dictionaries202
Load Factor204
Chapter 10. Strings and Regular Expressions209
10.1 Strings209
Delimiter Limitations2
10.2 Regular Expressions2
Chapter 1. Handling Exceptions233
1.1 Throwing and Catching Exceptions233
1.2 Exception Objects241
1.3 Custom Exceptions244
1.4 Rethrowing Exceptions246
Chapter 12. Delegates and Events251

Programming C#

12.2 Events268
Part I: Programming with C#277
Chapter 13. Building Windows Applications277
13.1 Creating a Simple Windows Form278
13.2 Creating a Windows Form Application289
13.3 XML Documentation Comments309
13.4 Deploying an Application311
Chapter 14. Accessing Data with ADO.NET321
14.1 Relational Databases and SQL321
14.2 The ADO.Net Object Model324
14.3 Getting Started with ADO.NET325
14.4 Using ADO Managed Providers328
14.5 Working with Data-Bound Controls330
14.6 Changing Database Records340
14.7 ADO.NET and XML353
Chapter 15. ProgrammingWeb Applications with Web Forms355
15.1 Understanding Web Forms355
15.2 Creating a Web Form358
15.3 Adding Controls361
15.4 Data Binding362
15.5 Responding to Postback Events369
15.6 ASP.NET and C#371
Chapter 16. Programming Web Services373
16.1 SOAP, WSDL, and Discovery373
16.2 Building a Web Service374
WSDL and Namespaces375
16.3 Creating the Proxy379
Part I: C# and the .NET CLR385
Chapter 17. Assemblies and Versioning385
17.1 PE Files385
17.2 Metadata385
17.3 Security Boundary385
17.4 Versioning385
17.5 Manifests386
17.6 Multi-Module Assemblies387
17.7 Private Assemblies395
17.8 Shared Assemblies395
Public Key Encryption397
Chapter 18. Attributes and Reflection401
18.1 Attributes401
18.2 Intrinsic Attributes401
18.3 Custom Attributes403
18.4 Reflection407
18.5 Reflection Emit416
Chapter 19. Marshaling and Remoting437
19.1 Application Domains438
19.2 Context446
Chapter 20. Threads and Synchronization457
20.1 Threads457
20.2 Synchronization465
20.3 Race Conditions and Deadlocks474
Chapter 21. Streams477
21.1 Files and Directories477
21.2 Reading and Writing Data487
21.3 Asynchronous I/O493
21.4 Network I/O497
21.5 Web Streams513
21.6 Serialization516
21.7 Isolated Storage523
Chapter 2. Programming .NET and COM527
2.1 Importing ActiveX Controls527
2.2 Importing COM Components534
2.3 Exporting .NET Components541
2.4 P/Invoke543
2.5 Pointers545
Appendix A. C# Keywords551

Programming C#

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

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

1. Handling Exceptions 1.1 Throwing and Catching Exceptions 1.2 Exception Objects 1.3 Custom Exceptions 1.4 Rethrowing Exceptions

12. Delegates and Events 12.1 Delegates 12.2 Events

I: Programming with C#

Programming C#

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

I: 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

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

2. Programming .NET and COM 2.1 Importing ActiveX Controls 2.2 Importing COM Components 2.3 Exporting .NET Components 2.4 P/Invoke 2.5 Pointers

A. C# Keywords Colophon

Programming C#

Preface

Every 10 years or so a new approach to programming hits like a tsunami. In the early 1980s, the new technologies were Unix, which could be run on a desktop, and a powerful new language called C, developed by AT&T. The early 90's brought Windows and C++. Each of these developments represented a sea change in the way you approached programming. .NET and C# are the next wave, and this book is intended to help you ride it.

Microsoft has `bet the company' on .NET. When a company of their size and influence spends billions of dollars and reorganizes its entire corporate structure to support a new platform, it is reasonable for programmers to take notice. It turns out that .NET represents a major change in the way you'l 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 development) to create a new language ideally suited for developing component-based n-tier distributed web applications.

About This Book

This book is a tutorial, both on C# and on writing .NET applications with C#. Part I focuses on the details of the language. If you are already proficient in a programming language, you may be able to skim this section, but be sure to read through Chapter 1, which provides an overview of the language and the .NET platform. If you are new to programming, you'l want to read the book as the King of Hearts instructed the White Rabbit: "Begin at the beginning, and go on till you come to the end: then stop."[1]

[1] Alice's Adventures in Wonderland by Lewis Carroll.

How the Book Is Organized

Part I of this book concentrates on the C# language. Part I details how to write .NET programs, and Part I describes how to use C# with the .NET Common Language Runtime library.

Part I

Chapter 1, introduces you to the C# language and the .NET platform.

(Parte 1 de 11)

Comentários