C# 2008
Programmer's Reference
Wei-Meng Lee
To my family and wife, Shihua, for their support and love.
About the Author
Wei-Meng Lee, Microsoft MVP, is a technologist and founder of Developer Learning Solutions (www.learn2develop.net), a technology company specializing in hands-on training in the latest Microsoft and Apple technologies.
Wei-Meng writes extensively for online publications such as DevX.com and the O'Reilly Network and magazines such as CoDe Magazine and asp.netPRO magazine on topics ranging from .NET to Mac OS X. He is also the author of Professional Windows Vista Gadgets Programming (Wrox) and Practical .NET 2.0 Networking Projects (Apress).
You can contact Wei-Meng at weimenglee@learn2develop.net.
About the Technical Editor
Andrew Mooreis a graduate of Purdue University-Calumet in Hammond, Indiana, and has been developing software since 1998 for radar systems, air traffic management, discrete-event simulation, and business communications applications using C, C++, C#, and Java on the Windows, UNIX, and Linux platforms. Andrew is the author of Wrox Blox articles titled "Create Amazing Custom User Interfaces with WPF, C#, and XAML in .NET 3.0,", ".NET 3.5 CD Audio Player," and "Power Programming with ReSharper." He is currently a senior software engineer at Interactive Intelligence, Inc. in Indianapolis developing Microsoft-based applications for business communications. Andrew lives in Indiana with his wife, Barbara, and children, Sophia and Andrew.
Credits
Acquisitions Editor
Katie Mohr
Development Editor
Maryann Steinhart
Technical Editor
Andrew Moore
Production Editor
Christine O'Connor
Copy Editor
Foxxe Editorial Services
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinator, Cover
Lynsey Stanford
Proofreader
C.M. Jones
Indexer
Robert Swanson
Acknowledgments
Writing a book is like running a long race — you need stamina, training, and perseverance. But these are not the most important factors that ensure you reach the finishing line. The most important factor is the motivation that keeps you going, on and on, even though you may be physically exhausted and don't think you can move any farther. While this is not the first book I have written, I am always very excited when embarking on a new book project. After the excitement comes a lot of hard work — coping with missed deadlines, changing work schedules, writer's block, and so forth.
For this book, I am extremely lucky to work with two very important people — my acquisitions editor, Katie Mohr, and development editor, Maryann Steinhart. Both Katie and Maryann have been very patient with me when the going gets tough. Katie has always egged me on, and offered many suggestions to scope the book to what it is today. Maryann has been the studious timekeeper, with a gentle but firm voice telling me to press forward when I missed the deadline. Maryann has also painstakingly read and reread every sentence I wrote, and I am always surprised with her attention to detail which has definitely made this book a better one. With heart-felt sincerity, I want to say a big thank you to both of them!
I would also like to thank the technical editor, Andrew Moore, for giving me many suggestions for improving the book. Writing this book has made me learn a lot of things I never knew. Thanks, Andrew!
Last but not least, I want to take this opportunity to thank my parents and my wife, Shihua, for their understanding and support when I have had to take time away to work on this book. Thanks!
Since the release of the Microsoft .NET Framework in July 2000, the C# programming language has gone through a few iterations to its latest version, 3.0. Over the years, the C# language has gained a lot of followers, partly due to its syntax, which is familiar to Java and C programmers. The clear syntax of the language made it easy to learn, and it's a popular choice for beginning programmers. In addition, the C# language is gaining a lot of traction in the Visual Basic camp, especially among VB6 programmers, who needed to move to .NET and did not want to learn a totally new variant of the Visual Basic language — Visual Basic .NET.
The latest version of C# 3.0 comes with .NET Framework 3.5. It contains many new features that makes the language more intuitive and powerful. Coupled with Visual Studio 2008, Microsoft's flagship development environment, developing applications using C# is now available to a wide audience.
In writing this book, I used the approach I believe is the easiest way to learn a new language — by examples. Often, books and articles get into too much of the theory without showing the readers what the concept looks like in code. For each topic, I try to provide numerous examples to illustrate the concept, and I would encourage you to make changes to the program to explore further. If you are an experienced programmer, you can jump directly to a particular chapter, as each chapter comes with independent examples.
Who This Book Is For
This book is for programmers of all levels. Beginning programmers should find the C# language easy to learn through the many code examples provided in each chapter. Experienced programmers can jump directly to individual chapters covering the topics of interest to them.
A conscious effort is made to illustrate each topic with independent code examples so that readers who want clarification on a topic do not need to wade through the entire chapter.
This book is ideal for the working programmer as well as students taking a semester course in C# programming. The sample projects covered in chapters 16 to 20 provide numerous project ideas as well as motivation for readers to get started working on bigger projects.
What This Book Covers
This book is divided into three parts. Part I covers the C# language fundamentals; Part II covers application development using C#, and Part III provides three appendices that cover the list of C# keywords, the .NET class libraries, and document generation using the Sandcastle utility.
Part I: C# Fundamentals
□ Chapter 1 introduces the .NET Framework. It examines the key components in the .NET Framework as well as the role played by each of the components. In addition, it discusses the relationships between the various versions of the framework, from version 1.0 to the latest 3.5.
□ Chapter 2 covers the use of Microsoft Visual Studio 2008 as the tool for C# development. Visual Studio 2008 is an extremely versatile and powerful environment for developing .NET applications. This chapter explores some of the common features that you will likely use in the process of your development work.
□ Chapter 3 introduces the syntax of the C# language and covers all the important topics: C# keywords, variables, constants, comments, XML documentation, data types, flow control, loops, operators, and preprocessor directives.
□ Chapter 4 tackles one of the most important topics in C# programming — classes and objects. Classes are essentially templates in from which you create objects. In C# .NET programming, everything you deal with involves classes and objects. This chapter provides a firm foundation in the use and creation of classes for code reuse.
Читать дальше