Cover image for C# in a nutshell
C# in a nutshell
Drayton, Peter.
Personal Author:
Second edition.
Publication Information:
Beijing ; Farnham : O'Reilly, [2003]

Physical Description:
xxiii, 897 pages : illustrations ; 23 cm + 1 CD-ROM (4 3/4 in)
General Note:
Previous ed.: 2002.

Includes index.
Format :


Call Number
Material Type
Home Location
Item Holds
QA76.73.C154 D73 2003 Book and Software Set Central Closed Stacks

On Order



C# in a Nutshell provides C# programmers with a concise and thorough reference to the language in one straightforward and accessible volume. Designed as a handbook for daily use, this book is an essential guide to the C# language and the base class APIs of the .NET Framework. Programmers will want to keep this book next to their keyboards for years to come.The heart of the book is a succinct but detailed reference to the C# language and the .NET types most essential to C# programmers. Each chapter in the API reference begins with an overview of a .NET namespace and a diagram of its types, including a quick-reference entry for each type, with name, assembly, category, description, member availability, class hierarchy, and other relevant information, such as whether the type is part o the ECMA CLI specification. Newly updated for .NET Framework version 1.1, the second edition also adds a CD that allows you to integrate the book's API Quick Reference directly into the help files of Visual Studio .NET 2002 & 2003, giving you direct access to this valuable information via your computer.In addition to the API reference section, this book includes:

An accelerated introduction to the C# language and the .NET Common Language Runtime A tutorial section on using C# with the core classes of the .NET Framework Class Library to perform common tasks such as manipulating strings, I/O, and interacting with legacy components Comprehensive language and tool reference chapters, including a C# syntax summary, a list of XML documentation tags, and a guide to command-line tools that ship with Visual Studio .NET and the .NET Framework Appendixes with reference tables for regular expression syntax, format specifiers, a C# keyword glossary, namespace/assembly cross-reference, and a type and member index for determining in which type a method or field is defined. Every once in a while, a book becomes the de-facto standard for a technology, operating system, or programming language--which is exactly what C# in a Nutshell has done in a single straightforward and easy to use volume. There is no more complete, up-to-date reference to the C# Language available.

Author Notes

Peter Drayton is an independent consultant, helping early-stage companies define and build systems that take advantage of technologies such as .NET, SOAP, XML, and COM+. Peter is also an instructor for DevelopMentor, where he teaches Essential C#.NET. Originally from Cape Town, South Africa, Peter now lives in the San Francisco Bay Area with his wife, Julie. He spends his spare time researching .NET and tinkering with a small flotilla of computers cluttering up their a partment. He can be reached at

Ben Albahari is cofounder of Genamics, a provider of tools for C# and J++ programmers, as well as software for DNA and protein sequence analysis. He is author of A Comparative Overview of C#, a frequently cited comparison of C# with C/C++ and Java that was recently named by DevX as one of the top 10 .NET sites. Ben is a resident of Perth, Australia, and in his spare time enjoys composing music on his computer. He can be reached at

Ted Neward is an independent software development architect and mentor in the Sacramento, California area. He is the author of a number of books, including Server-Based Java Programming (Manning), the forthcoming EffectiveEnterprise Java (Addison-Wesley) and Shared Source CLI Essentials (O'Reilly) and co-author of C# In a Nutshell (O'Reilly) with Peter Drayton and Ben Albahari. He is also an instructor with DevelopMentor, where he teaches and authors both the Java and .NET curriculum. He speaks frequently for technology user groups and writes technical papers for and He currently labors on behalf of the University of California, Davis, architecting a rebuild of the Davis Accounting and Financial Information Services software system. Past clients include companies like Pacific Bell, EdFund, Synergex and Intuit.

Table of Contents

Prefacep. xiii
Part I. Programming with C#
1. Introducing C# and the .NET Frameworkp. 3
The C# Languagep. 4
The .NET Frameworkp. 7
ECMA Standardizationp. 11
Changes in Visual C# 2003p. 13
2. C# Language Basicsp. 14
A First C# Programp. 14
Identifiers and Keywordsp. 15
Type Basicsp. 15
Value Types and Reference Typesp. 19
Predefined Typesp. 24
Arraysp. 28
Variables and Parametersp. 30
Expressions and Operatorsp. 33
Statementsp. 36
Namespacesp. 42
3. Creating Types in C#p. 45
Classesp. 45
Inheritancep. 55
Access Modifiersp. 61
Structsp. 63
Interfacesp. 63
Enumsp. 66
4. Advanced C# Featuresp. 68
Delegatesp. 68
Delegates Versus Function Pointersp. 70
Delegates Versus Interfacesp. 70
Eventsp. 70
Operator Overloadingp. 73
Try Statements and Exceptionsp. 76
Attributesp. 79
Unsafe Code and Pointersp. 81
Preprocessor Directivesp. 84
XML Documentationp. 85
Part II. Programming with the .NET Framework
5. Framework Class Library Overviewp. 93
Core Typesp. 93
Textp. 94
Collectionsp. 94
Streams and I/Op. 94
Networkingp. 95
Threadingp. 95
Securityp. 95
Reflection and Metadatap. 95
Assembliesp. 96
Serializationp. 96
Remotingp. 96
Web Servicesp. 97
Data Accessp. 97
XMLp. 98
Graphicsp. 98
Rich Client Applicationsp. 98
Web-Based Applicationsp. 98
Globalizationp. 99
Configurationp. 99
Advanced Component Servicesp. 99
Diagnostics and Debuggingp. 100
Interoperating with Unmanaged Codep. 100
Compiler and Tool Supportp. 100
Runtime Facilitiesp. 101
Native OS Facilitiesp. 101
Undocumented Typesp. 101
6. String Handlingp. 103
String Classp. 103
StringBuilder Classp. 106
Regular Expression Supportp. 106
Regular Expression Basicsp. 107
Procedural- and Expression-Based Patternsp. 110
Cookbook Regular Expressionsp. 111
7. Collectionsp. 115
Iterating Over Collectionsp. 115
Standard Collection Interfacesp. 119
Predefined Collection Classesp. 121
Ordering Instancesp. 124
Generating Hash Codep. 125
8. XML I/Op. 127
Accessing XML Documentsp. 127
Parsing an XML Streamp. 131
Selecting Nodes Using XPathp. 131
Transforming a Document Using XSLTp. 134
9. Networkingp. 137
Network Programming Modelsp. 137
Generic Request/Response Architecturep. 137
HTTP-Specific Supportp. 138
WebClientp. 139
Adding New Protocol Handlersp. 139
Using TCP, UDP, and Socketsp. 139
Using DNSp. 141
10. Streams and I/Op. 142
Streams and Backing Storesp. 142
Encapsulating Raw Streamsp. 144
Directories and Filesp. 146
Isolated Storagep. 150
11. Serializationp. 152
What Is Serialization?p. 152
Serialization Support in the Frameworkp. 153
Explicit Serializationp. 153
Implicit Serializationp. 154
[Serializable]p. 155
[NonSerialized]p. 156
IDeserializationCallbackp. 156
ISerializablep. 157
[Serializable] and ISerializablep. 158
12. Assembliesp. 161
Elements of an Assemblyp. 161
Assemblies and Modulesp. 162
Scoping Types and Type Referencesp. 162
Naming and Signing Assembliesp. 163
Resolving and Loading Assembliesp. 165
Deploymentp. 165
Security Permissionsp. 166
13. Reflectionp. 167
Type Hierarchyp. 167
Types, Members, and Nested Typesp. 168
Retrieving the Type for an Instancep. 169
Retrieving a Type Directlyp. 169
Reflecting Over a Type Hierarchyp. 170
Late Bindingp. 170
Advanced Uses of Reflectionp. 172
Creating New Types at Runtimep. 173
14. Custom Attributesp. 175
Language Supportp. 175
Compiler Supportp. 175
Runtime Supportp. 176
Predefined Attributesp. 177
Defining a New Custom Attributep. 179
Retrieving a Custom Attribute at Runtimep. 180
15. Memory Managementp. 182
The Garbage Collectorp. 182
Optimization Techniquesp. 183
Finalizersp. 184
Dispose and Close Methodsp. 184
16. Threadingp. 186
Thread Synchronizationp. 186
Common Thread Typesp. 189
Asynchronous Delegatesp. 190
17. Integrating with Native DLLsp. 192
Calling Into DLLsp. 192
Marshaling Common Typesp. 193
Marshaling Classes and Structsp. 193
In and Out Marshalingp. 194
Callbacks from Unmanaged Codep. 195
Simulating a C Unionp. 195
Mapping a Struct to a Binary Formatp. 197
Predefined Interop Support Attributesp. 199
18. Integrating with COM Componentsp. 202
Binding COM and C# Objectsp. 202
Exposing COM Objects to C#p. 202
Exposing C# Objects to COMp. 203
COM Mapping in C#p. 204
Common COM Interop Support Attributesp. 205
COM+ Supportp. 205
19. Diagnosticsp. 208
Logging and Assertion Facilitiesp. 208
Conditional Compilationp. 210
Debugger Integrationp. 211
Processes, Threads, and Stacksp. 211
Event Logsp. 214
Performance Countersp. 216
20. C# Language Referencep. 220
Part III. Language and Tools Reference
21. XML Documentation Tag Referencep. 229
22. C# Naming and Coding Conventionsp. 232
Casep. 232
Mechanicsp. 234
Word Choicep. 235
Namespacesp. 236
23. C# Development Toolsp. 237
Part IV. API Quick Reference
24. How to Use This Quick Referencep. 273
25. The Microsoft.Win32 Namespacep. 279
26. Systemp. 289
27. System.Collectionsp. 392
28. System.Collections.Specializedp. 409
29. System.Diagnosticsp. 417
30. System.Globalizationp. 458
31. System.IOp. 479
32. System.IO.IsolatedStoragep. 508
33. System.Netp. 513
34. System.Net.Socketsp. 544
35. System.Reflectionp. 558
36. System.Reflection.Emitp. 598
37. System.Runtime.InteropServicesp. 628
38. System.Runtime.Serializationp. 658
39. System.Runtime.Serialization.Formattersp. 670
40. System.Textp. 676
41. System.Text.RegularExpressionsp. 684
42. System.Threadingp. 692
43. System.Timersp. 712
44. System.Xmlp. 715
45. System.Xml.XPathp. 753
46. System.Xml.Xslp. 761
Part V. Appendixes
A. Regular Expressionsp. 769
B. Format Specifiersp. 773
C. Data Marshalingp. 779
D. C# Keywordsp. 781
E. Namespaces and Assembliesp. 787
Type, Method, Property, Event, and Field Indexp. 793
Indexp. 851