Programming Microsoft
Visual C# 2005: The
Language
byDonis Marshall
Microsoft Press
2006 (704 pages)
ISBN:0735621810
Offering expert guidance,
hands-on programming
instruction, and practical
examples, this straightforward
book will help both new and
experienced developers
advance their proficiency in
developing applications for
Microsoft Windows and the Web.
Table of Contents
Programming Microsoft Visual C# 2005-The Language
Introduction
Part I - Core Language
Chapter 1 - Introduction to Visual C# Programming
Chapter 2 - Types
Chapter 3 - Inheritance
Part II - Core Skills
Chapter 4 - Introduction to Visual Studio 2005
Chapter 5 - Arrays and Collections
Chapter 6 - Generics
Chapter 7 - Iterators
Part III - More C# Language
Chapter 8 - Delegates and Events
Chapter 9 - Exception Handling
Part IV - Debugging
Chapter 10 - Metadata and Reflection
Chapter 11 - MSIL Programming
Chapter 12 - Debugging with Visual Studio 2005
Chapter 13 - Advanced Debugging
Part V - Advanced Concepts
Chapter 14 - Memory Management
Chapter 15 - Unsafe Code
Appendix A - Operator Overloading
Index
List of Figures
List of Tables
Back Cover
Get hands-on, expert guidance for developing with Visual C# 2005.
Get the essential, straightforward information you need to master the core capabilities of Visual C#
2005. Both new and experienced developers get expert guidance, hands-on programming instruction,
and practical examples to help advance their proficiency in developing applications for Microsoft
Windows and the Web.
Discover how to:
Refine class usage with inheritance, polymorphism, and other strategies
Implement generics to define a type-safe data structure
Work with stacks, queues, arrays, dictionaries, and other collections
Use iterators to implement and standardize enumerator patterns
Know when to catch exceptions-and handle them locally or propagate them
Interrogate metadata and facilitate late binding by using reflection
Synchronize threads with locks, events, mutexes, and other tools
Use the Microsoft Visual Studio Debugger and explore advanced debugging techniques and
tools
About the Author
Donis Marshall is a trainer, a consultant and an author with 20 years of development experience and
an in-depth background on Microsoft .NET technologies. He is the author of several books, including
.NET Security Programming. Donis teaches classes on .NET programming, debugging, security, and
design and architecture. In addition, he is the president of DebugNow.
Programming Microsoft Visual C# 2005-The
Language
Donis Marshall
PUBLISHED BY Microsoft Press A Division of Microsoft Corporation
One Microsoft Way Redmond, Washington 98052-6399
Copyright © 2006 by Donis Marshall
ISBN:0735621810
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or
by any means without the written permission of the publisher.
Library of Congress Control Number 2005934153
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 QWT 0 9 8 7 6 5
Distributed in Canada by H.B. Fenn and Company Ltd.
A CIP catalogue record for this book is available from the British Library.
Microsoft Press books are available through booksellers and distributors worldwide. For further
information about international editions, contact your local Microsoft Corporation office or contact
Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at
www.microsoft.com/mspress. Send comments to mspinput@microsoft.com.
Microsoft, IntelliSense, Microsoft Press, MSDN, Visual Basic, Visual C#, Visual Studio, the Visual
Studio logo, Win32, Windows, Windows CE, the Windows logo, Windows NT, and WinFX are either
registered trademarks or trademarks of Microsoft Corporation in the United States and/or other
countries. Other product and company names mentioned herein may be the trademarks of their
respective owners.
The example companies, organizations, products, domain names, e-mail addresses, logos, people,
places, and events depicted herein are fictitious. No association with any real company, organization,
product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred.
This book expresses the author's views and opinions. The information contained in this book is provided
without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its
resellers, or distributors will be held liable for any damages caused or alleged to be caused either
directly or indirectly by this book.
Acquisitions Editor: Ben Ryan
Project Editor: Valerie Woolley
Technical Editor: James D. Rogers
Copy Editor: Nancy Sixsmith
Indexer: Tony Ross and Lee Ross
Body Part No. X11-50074
This book is dedicated to my father, Herbert Marshall. He was a nuclear engineer, an artist, a
confidant, a doting husband to my mother, and most of all a compassionate person. He was a giant
amongst men and touched innumerable lives. His three sons, including myself, miss him every day.
Acknowledgments
Programming Microsoft Visual C# 2005: The Language was completed with the collaboration of several
people. I am credited on the cover, but the contribution of others is no less important. I want to
especially acknowledge the contributions of Valerie Woolley, Ben Ryan, and Jim Rogers. If possible,
they would also receive cover credit. Valerie was the project manager and provided support,
encouragement, patience, and the occasional nudge when necessary. Ben, who was the acquisitions
editor, had unyielding confidence in my ability, which is greatly appreciated. Jim Rogers was the
technical editor and diligently reviewed hundreds of pages of manuscript and code. He helped assure
the superb quality of the book.
I also want to thank John Bruno, who is an exceptional engineer, for reviewing and commenting on each
chapter, which was very helpful.
Writing a book is an all-consuming project. Unfortunately, much of this burden is carried by friends and
loved ones. I appreciate the patience and support of my mother, Lynn, and of my friends Herb, Jr.,
Chuck, and Patty, along with a long list of other friends who were treated shabbily during this project.
Thanks for your understanding.
Finally, I want to acknowledge my children: Jason, Kristen, and Adam. They make every day special.
They are my motivation. A special acknowledgment is reserved for Jason. During most of this project,
Jason was stationed in Iraq as a Marine. He recently returned home safely. We are proud of you.
Donis Marshall
Donis Marshall is currently one of the few trainers endorsed by Microsoft Global Learning Services to
conduct Microsoft technology classes for Microsoft employees. In this capacity, Mr. Marshall travels
internationally, delivering dozens of classes to Microsoft developers and engineers in the United States,
Europe, and Asia. His repertoire includes classes on Advanced .NET UMD Debugging, Advanced .NET
Debugging workshops, .NET Design and Architecture, Visual Basic .NET Programming, .NET
Interoperability and Security, .NET Web Services, and ASP.NET. He also teaches .NET classes at
Autodesk, NCCI, and NASA.
Donis Marshall is a nationally recognized teacher of computer technology to developers and scientists.
As founder and lead instructor for The Training Alliance, he taught advanced technical classes for many
Fortune 500 clients. He also managed a staff of technical instructors as Director of Advanced Technical
Learning Services at Productivity Point International, a national franchiser of training services.
Mr. Marshall is President of DebugNow (www.debugnow). DebugNow offers an assortment of innovative
tools for support engineers and developers to debug and monitor Win32 and .NET applications.
As a contractor, Donis Marshall has written thousands of lines of code for various entities.
Introduction
Microsoft Visual C# 2005 includes several enhancements to earlier versions of the language. If you want
to learn the new features of the language, Programming Microsoft Visual C# 2005: The Language offers
detailed explanations of each improvement. One of the most awaited additions to the .NET environment
is generics. Other additions include anonymous methods, static classes, and new classes that affect
garbage collection. This book introduces these new features, provides context, and displays sample
code.
Enhancements are not limited to the language. The Microsoft Visual Studio IDE has also been
enhanced in Visual Studio 2005. Microsoft continues to expand upon the impressive assortment of rapid
application development (RAD) tools that are available. The Exception Assistant, code snippets, and
visualizers are some of the more notable advancements, where the emphasis is on providing helpful
information that markedly increases developer productivity. This book details these and other
improvements to previous versions of Visual Studio.
A larger portion of the lifetime of an application is spent in maintenance and debugging. Efficient and
effective debugging tools and techniques can facilitate a more robust application, which reduces the
need to debug. You can also resolve problems more quickly when they inevitably occur. A managed
application has a managed veneer and an unmanaged underpinning. Debugging requires an
understanding of both realms where a managed application exists: managed and unmanaged. From a
debugging context, Chapter 12 examines both realms of a managed application and helps developers
understand how to effectively debug a managed application.
Who Is This Book For?
Programming Microsoft Visual C# 2005: The Language is for developers who want a comprehensive
explanation of Visual C# 2005 or want to explore a specific aspect of the language. It is a composite of
chapters sequenced to provide a rational and complete review of the language. Each chapter is also
reviewable as an independent unit that encapsulates a specific topic.
This book targets both professional and casual developers. Practical, in-depth explanations are offered
for even the most ardent developers. Sample code is provided as a complement to the content. For
casual developers, code is often the clearest explanation of in-depth concepts. Actually, even for
professional developers, sample code is often invaluable. For this reason, this book contains reams of
code examples.