Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596527570/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
Each release of C# and the .NET Framework brings new features and greater potential for productivity. C# 3.0 introduces the most significant enhancements to the language yetwith a unified querying syntax called Language Integrated Query , or LINQ. LINQ bridges the traditional divide between programs and their data sourcesas well as bringing C# closer to functional languages such as LISP and Haskell.
The price of this growth is that there's now more to learn. While tools such as Microsoft's IntelliSenseand online referencesare excellent in helping you on the job, they presume an existing map of conceptual knowledge . This book provides exactly that map of knowledge in a concise and unified stylefree of clutter and long introductions.
Unlike earlier editions, C# 3.0 in a Nutshell is organized entirely around concepts and use cases, making it friendly both to sequential reading and random browsing. It also plumbs significantly greater depths than before while assuming less background knowledgemaking it the most accessible edition yet.
This book covers C#, the CLR, and the core Framework assemblies. We've chosen this focus to allow space for difficult topics such as threading, security, and application domainswithout compromising depth or readability. Features new to C# 3.0 and the associated Framework are flagged so that you can also use this book as a C# 2.0 reference.
Intended Audience
This book targets intermediate to advanced audiences. No prior knowledge of C# is required, but some general programming experience is necessary. For the beginner, this book complements, rather than replaces, a tutorial-style introduction to programming.
If you're already familiar with C# 2.0, you'll find more than a hundred pages dedicated to LINQ and other new C# 3.0 features. In addition, many other chapters are designed to lift your existing knowledge of C# and the core Framework.
This book is an ideal companion to any of the vast array of books that focus on an applied technology such as WPF, ASP.NET, or WCF. The areas of the language and .NET Framework that such books omit, C# 3.0 in a Nutshell covers in detailand vice versa.
If you're looking for a book that skims every .NET Framework technology, this is not for you. This book is also unsuitable if you want a replacement for IntelliSense (i.e., the alphabetical listings of types and type members that appeared in previous editions).
How This Book Is Organized
The first three chapters after the introduction concentrate purely on C#, starting with the basics of syntax, types, and variables, and finishing with advanced topics such as unsafe code and preprocessor directives. If you're new to the language, you should read these chapters sequentially, with the exception of
The remaining chapters cover the core .NET Framework, including such topics as LINQ, XML, collections, I/O and networking, memory management, reflection, attributes, security, threading, application domains, and native interoperability. You can read most of these chapters randomly, except for , which lay a foundation for subsequent topics. The three chapters on LINQ are also best read in sequence.
What You Need to Use This Book
The examples in this book require a C# 3.0 (or 2.0) compiler in conjunction with the Microsoft .NET Framework 3.5 (or 3.0/2.0). You will also require Microsoft's .NET documentation. The easiest way to get all threealong with an integrated development environmentis to install Microsoft Visual Studio. Any edition is suitable for what's taught in this book, including Visual Studio Express (currently a free download). Visual Studio also includes an express edition of SQL Server, required to run the LINQ to SQL examples, and IntelliSense, which pops up type member listings as you type.
Another option, if you don't mind using a plain-text editor and building at the command line, is to download the .NET Framework SDK. This includes the compiler, .NET documentation, and additional command-line tools.
The lightest option is to download and install just the Microsoft .NET Framework Runtime. This includes the command-line compiler; however, it doesn't include other command-line tools or any documentation.
Conventions Used in This Book
is a sample diagram depicting how we illustrate types throughout this book. Abstract classes are shown as a slanted rectangle, and interfaces are shown as a circle. Inheritance is shown as a solid line from the subtype, ending with a hollow triangle that points to the supertype. We use a line with a solid diamond to annotate any kind of relationship (whether an association, aggregation or composition).
Figure 1. Sample diagram
The following typographical conventions are used in this book:
ItalicIndicates new terms, URIs, filenames, and directories
Constant width
Indicates C# code, keywords and identifiers, and program output
Constant width bold
Shows a highlighted section of code
Constant width italic
Shows text that should be replaced with user-supplied values
Tip
This icon signifies a tip, suggestion, or general note.
Warning
This icon indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: " C# 3.0 in a Nutshell , by Joseph Albahari and Ben Albahari. Copyright 2007 Ben Albahari and Joseph Albahari, 978-0-596-52757-0."