Preface

Who This Book Is For

Visual C# 2005: A Developer’s Notebook is written for programmers who are already familiar with previous version of C# (C# 1.0 or 1.1) and who have used a previous version of Visual Studio .NET (either 2002 or 2003) to build Windows (Windows Forms) or web-based (ASP.NET) applications. My aim is to introduce you, through a series of hands-on labs, to the new features of the C# 2.0 language, the .NET 2.0 Framework, and the Visual Studio 2005 developer environment.

To get the most out of this book you’ll need a copy of Visual Studio 2005 that supports C# programming. I encourage you to work your way through the labs as they are purposefully small and to the point. However, the complete source code, along with an errata sheet, a FAQ list, and links to a private support discussion center, are available on my web site, http://www.LibertyAssociates.com (just click Books and scroll down to Visual C# 2005: A Developer’s Notebook), or at the O’Reilly web page for this book, http://www.oreilly.com/catalog/visualcadn.

Tip

This book went to press before the final release of Beta 2 was ready. All screenshots and code were validated against the February 2005 Community Techinal Preview. For final Beta 2 changes, please visit the O’Reilly web site for this book or visit my own web site.

Visual C# 2005: A Developer’s Notebook covers very little of the material an experienced C# programmer already knows. My goal is to help you build on your current knowledge, not to waste your time demonstrating old material.

Similarly, this book does not try to be exhaustive when it comes to building Windows and web applications with the .NET 2.0 Framework or the Visual Studio 2005 developer environment. The goal is to introduce you to what is new in the language, the development environment, and the class libraries, and to equip you for further exploration of those areas that are likely to be of interest to you.

Tip

If you are not yet familiar with C# and Visual Studio, you might prefer to read Programming C# (O’Reilly), which teaches the entire language without assuming you are already an experienced .NET programmer.

If you are a proficient VB.NET (as opposed to VB6) programmer, on the other hand, read on; this book will teach you what you need to know to make the jump from VB.NET to C# 2.0, all in one go. (Although you’ll have to work a bit harder than a C# 1.x programmer, I believe you’ll find that most of the syntactic differences between VB and C# are trivial and obvious.) For more information, see the C# AND VB.NET Conversion Pocket Reference (O’Reilly).

How This Book Is Organized

The goal of Visual C# 2005: A Developer’s Notebook is to equip you to create meaningful applications; not just to learn about changes to the C# language. The book is organized into five chapters. Each chapter consists of a series of labs, each of which introduces a new feature, shows how it’s used, and then walks you through an example, explaining the details you need to understand along the way. Each lab includes a “What about...” section that attempts to anticipate and answer follow-up questions, as well as (perhaps most importantly) a section that tells you where you can learn more about each topic.

Chapter 1 explains what is new in the language. We start by examining one of the most anticipated features of C# 2.0, generics, and we explore them in-depth. The chapter also includes coverage of the new iterators, anonymous methods, and partial types that are part of C# 2.0, as well as static classes, nullable types, accessing objects in the Global namespace, and limiting access to fields within properties. The chapter closes with a brief discussion of delegate covariance and contravariance.

Chapter 2 explores the changes and improvements made to Visual Studio 2005. You will see how to configure the new development platform and how to put the enhanced editor to work for you. A very exciting new feature within Visual Studio 2005 is automated refactoring. The software also now offers better support for code re-use through predefined code snippets. Debugging is discussed and the new visualizers are demonstrated.

Because I assume you’re learning C# 2.0 to create applications, the rest of the book focuses on just that. Chapter 3 demonstrates the new features available to you for creating Windows applications, including the new ToolStrips, masking, auto-complete text boxes, split windows, and support for adding Windows system sounds. The new data controls for Windows Forms are demonstrated, as is ClickOnce deployment, a new feature that greatly improves the feasibility of using rich clients or so-called Smart Clients, for certain kinds of networked applications.

Chapter 4 is all about new features for building web applications, some of which are found in the ASP.NET 2.0 Framework libraries and others in the Visual Studio 2005 IDE. The goal of the ASP.NET 2.0 development team was to make it possible to build web applications with 75% less code than was required for ASP.NET 1.x applications. Their success is remarkable. Chapter 4 covers the new controls that facilitate security, authentication, and personalization, as well as new support for creating uniform and coherent sites with themes and master pages.

Finally, Chapter 5 focuses on the new .NET 2.0 controls for data access along with revisions to the ADO.NET classes. Topics include creating master/detail records with no code and integrating XML data sources into your application.

Where Can I Learn More?

The goal of this book is to introduce you to new features of C# 2.0, .NET 2.0, and the Visual Studio 2005 developer environment that are likely to be of greatest interest to C# programmers. The Developer’s Notebook series is not an exhaustive reference. Thus, at the end of each lab you’ll find a section titled “Where can I learn more?” Here I will point you to books, magazine articles, online resources, Microsoft Developer Network (MSDN) articles, and Visual Studio 2005 Help entries and tell you where you can find more detail or obtain another perspective. When I refer to the MSDN Library, I am generally referring to the MSDN Library that is available to you through the installed Visual Studio 2005 Help, or online at http://msdn.microsoft.com/library. MSDN subscribers also receive the library on DVD from time to time as part of their regular monthly updates. I also point to articles and resources found elsewhere at the official MSDN site, or at related sites such as Channel 9 (http://channel9.msdn.com/default.aspx) and GotDotNet (http://www.gotdotnet.com).

Tip

To find the online resources, go to my web site (http://www.LibertyAssociates.com) and click Books. Scroll down to Visual C# 2005: A Developer’s Notebook, and click Where Can I Learn More? This will take you to a page with links to every online article mentioned in the book.

What You Need to Use This Book

The most important requirement for this book is a solid familiarity with C# 1.x and experience building .NET applications. I do not hold your hand through the fundamentals; instead, I focus on what is new in the 2005 edition.

You’ll want a computer with a version of Visual Studio 2005 installed that supports C# 2.0, along with one or another form of SQL Server (SQL Server Express is fine).

You can also do the labs in this book using the new Visual Studio Express Editions. You’ll need both Visual C# 2005 Express Edition (for Chapters Chapter 1, Chapter 2, Chapter 3, and Chapter 5) and Visual Web Developer 2005 Express Edition (for Chapter 4).

Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard accelerators (such as Alt and Ctrl).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, and the output from commands.

Constant width bold

Shows commands and other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Tip

This signifies a tip, suggestion, or general note.

Warning

This indicates a warning or caution.

Note

This indicates a Developer’s Note.

Using Code Examples

This book is 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: "Visual C# 2005: A Developer’s Notebook, First Edition, by Jesse Liberty. Copyright 2005 O’Reilly Media, Inc., 0-596-00799-X.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

I’d Like to Hear from You

Please send all your comments, suggestions, and (horrors!) errata to . Please check the FAQ list and errata sheet on my web site (http://www.LibertyAssociates.com; click Books) first, though, as someone might have already reported your error or asked your question.

You can get extensive help through the private discussion group provided for this book. Sign up through my web site. Then follow the link to the discussion forum provided at the top of the Books page.

Comments and Questions

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/visualcadn

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Safari Enabled

image with no caption

When you see a Safari® enabled icon on the cover of your favorite technology book that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

The author is deeply grateful to O’Reilly Media for inventing this incredible series, and to John Osborn both for bringing me into O’Reilly and for letting me write this book.

This book has had some of the best technical editors I’ve ever had the pleasure to work with, including Nicholas Paldino, Luke Hoban, Michael Weinhardt, and Bill Hamilton.

In addition, a number of faithful readers agreed to provide feedback while the book was being written, including Cristof Falk, Frank Gilgic, Christopher Kimpbell, Daniel O’Connel, Jon Skeet, Dan Nash, Zheng Tianbo, Colin Young, Girish Bharadwaj, Brian Bischof, David Bench, Mattias Sjogren, Jouko Kynsijarvi, Rob Bazinet, Rakesh Rajan, Willem van Rumpt, Joseph Sign, Michael Rodriguez, Jon George, Ross Gray, Vance Kessler, James Thomas, David Novak, and especially Sahil Malik, Carel Blumenstock, Rolf M. Marsh, Michael Taylor, and Jamie McQuay. Their help was invaluable.

Dedication

This book is dedicated to the 70 million victims of AIDS who became ill due to the initial indifference of others. Writing good code is a great calling, as long as we look up from the computer once in a while.

Get Visual C# 2005: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.