stackalloc An operator that returns a pointer to a specified number of value types allocated on the stack.. static A type member modifier that indicates that the member applies to the
Trang 1Release TeamOR [x] NET
Trang 2Preface 2
About This Book 2
How the Book Is Organized 2
Who This Book Is For 5
C# Versus Visual Basic NET 5
C# Versus Java 5
C# versus C++ 5
Conventions Used in This Book 6
Support 6
We’d Like to Hear from You 7
Acknowledgements 7
Part I: The C# Language 8
Chapter 1 C# and the NET Framework 8
The NET Platform 8
The NET Framework 9
Compilation and the MSIL 10
The C# Language 11
Chapter 2 Getting Started:"Hello World" 12
Classes, Objects, and Types 12
Developing "Hello World" 17
Just In Time Compilation 20
Using the Visual Studio NET Debugger 20
Chapter 3 C# Language Fundamentals 22
Types 23
The Stack and the Heap 24
Variables and Constants 26
WriteLine( ) 26
Expressions 32
Whitespace 32
Statements 33
Statement Blocks 36
All Operators Are Not Created Equal 37
Whitespace and Braces 43
Operators 46
Trang 3Short-Circuit Evaluation 51
Namespaces 53
Preprocessor Directives 54
Chapter 4 Classes and Objects 57
Defining Classes 58
Creating Objects 62
Using Static Members 67
Static Methods to Access Static Fields 70
Destroying Objects 70
How Finalize Works 71
Passing Parameters 73
Overloading Methods and Constructors 77
Encapsulating Data with Properties 80
Readonly Fields 82
Chapter 5 Inheritance and Polymorphism 83
Specialization and Generalization 84
About the Unified Modeling Language 84
Inheritance 86
Polymorphism 89
Abstract Classes 94
The Root of all Classes: Object 97
Boxing and Unboxing Types 99
Nesting Classes 101
Nesting Classes 102
Using the operator Keyword 104
Supporting Other NET Languages 105
Creating Useful Operators 105
Logical Pairs 105
The Equals Operator 105
Conversion Operators 106
Chapter 7 Structs 111
Defining Structs 111
Creating Structs 113
Chapter 8 Interfaces 117
Mix Ins 117
Implementing an Interface 117
Trang 4Accessing Interface Methods 127
Overriding Interface Implementations 133
Explicit Interface Implementation 136
Chapter 9 Arrays, Indexers, and Collections 144
Arrays 144
The foreach Statement 148
Indexers 160
Collection Interfaces 168
Array Lists 172
Queues 182
Stacks 184
Dictionaries 187
Load Factor 188
Chapter 10 Strings and Regular Expressions 192
Strings 192
Delimiter Limitations 205
Regular Expressions 205
Chapter 11 Handling Exceptions 214
Throwing and Catching Exceptions 215
Exception Objects 223
Custom Exceptions 225
Rethrowing Exceptions 227
Chapter 12 Delegates and Events 230
Delegates 231
Events 248
Chapter 13 Building Windows Applications 256
Creating a Simple Windows Form 257
Creating a Windows Form Application 268
It’s Turtles, All the Way Down 274
XML Documentation Comments 288
Chapter 14 Accessing Data with ADO.NET 289
Relational Databases and SQL 290
The ADO.Net Object Model 293
Getting Started with ADO.NET 294
Using ADO Managed Providers 297
Working with Data-Bound Controls 300
Trang 5Changing Database Records 309
ADO.NET and XML 322
Chapter 15 ProgrammingWeb Applications with Web Forms 322
Understanding Web Forms 322
Creating a Web Form 325
Adding Controls 328
Data Binding 330
Responding to Postback Events 337
ASP.NET and C# 339
Chapter 16 Programming Web Services 339
SOAP, WSDL, and Discovery 339
Building a Web Service 340
WSDL and Namespaces 342
Creating the Proxy 346
Part III: C# and the NET CLR 349
Chapter 17 Assemblies and Versioning 349
PE Files 349
Metadata 349
Security Boundary 350
Versioning 350
Manifests 350
Multi-Module Assemblies 352
Private Assemblies 359
Shared Assemblies 359
Public Key Encryption 361
Chapter 18 Attributes and Reflection 364
Attributes 364
Intrinsic Attributes 365
Custom Attributes 366
Reflection 370
Reflection Emit 379
Chapter 19 Marshaling and Remoting 400
Application Domains 401
Context 409
Remoting 411
Trang 6Programming C#
page 514
sizeof
An operator that returns the size in bytes of a struct
stackalloc
An operator that returns a pointer to a specified number of value types allocated on the
stack
static
A type member modifier that indicates that the member applies to the type rather than an instance of the type
string
A predefined reference type that represents an immutable sequence of Unicode characters
struct
A value type that combines data and functionality in one unit
switch
A selection statement that allows a selection of choices to be made based on the value of a predefined type
this
A variable that references the current instance of a classor struct
throw
A jump statement that throws an exception when an abnormal condition has occurred
true
A Boolean literal
try
A statement that provides a way to handle an exception or a premature exit in a statement block
typeof
An operator that returns the type of an object as a System.Type object
uint
A four-byte unsigned integral datatype
Trang 7Programming C#
page 515
ulong
An eight-byte unsigned integral datatype
unchecked
A statement or operator that prevents arithmetic bounds checking on an expression
unsafe
A method modifier or statement that permits pointer arithmetic to be performed within a particular block
ushort
A two-byte unsigned integral datatype
using
Specifies that types in a particular namespace can be referred to without requiring their fully qualified type names The using statement defines a scope At the end of the scope the object
is disposed
value
The name of the implicit variable set by the set accessor of a property
virtual
A class method modifier that indicates that a method can be overridden by a derived class
void
A keyword used in place of a type for methods that don't have a return value
volatile
Indicates that a field may be modified by the operating system or another thread
while
A loop statement to iterate a statement block while an expression at the start of each
iteration evaluates to false