Introducing Visual Basic 2005 and the .NET Platform ■CHAPTER 1 the Philosophy of .NET
Total Page:16
File Type:pdf, Size:1020Kb
5785ch00FM.qxd 3/31/06 3:31 PM Page i Pro VB 2005 and the .NET 2.0 Platform Second Edition Andrew Troelsen 5785ch00FM.qxd 3/31/06 3:31 PM Page ii Pro VB 2005 and the .NET 2.0 Platform Copyright © 2006 by Andrew Troelsen All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-578-7 ISBN-10 (pbk): 1-59059-578-5 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Ewan Buckingham Technical Reviewer: Don Reamey Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Kier Thomas, Matt Wade Production Director and Project Manager: Grace Wong Copy Edit Manager: Nicole LeClerc Senior Copy Editor: Ami Knox Assistant Production Director: Kari Brooks-Copony Production Editor: Kelly Winquist Compositor and Artist: Kinetic Publishing Services, LLC Proofreaders: April Eddy, Lori Bring, Nancy Sixsmith Indexer: Broccoli Information Management Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. You will need to answer questions pertaining to this book in order to successfully download the code. 5785ch00FM.qxd 3/31/06 3:31 PM Page iii To my wife Mandy. Thank you babes for supporting me in yet another book. I love you. 5785ch00FM.qxd 3/31/06 3:31 PM Page iv 5785ch00FM.qxd 3/31/06 3:31 PM Page v Contents at a Glance About the Author . xxxiii About the Technical Reviewer. xxxv Acknowledgments . xxxvii Introduction . xxxix PART 1 ■ ■ ■ Introducing Visual Basic 2005 and the .NET Platform ■CHAPTER 1 The Philosophy of .NET . 3 ■CHAPTER 2 Building Visual Basic 2005 Applications . 31 PART 2 ■ ■ ■ Visual Basic 2005 Language Fundamentals ■CHAPTER 3 VB 2005 Programming Constructs, Part I . 65 ■CHAPTER 4 VB 2005 Programming Constructs, Part II. 103 PART 3 ■ ■ ■ Core Object-Oriented Programming Techniques ■CHAPTER 5 Defining Encapsulated Class Types. 127 ■CHAPTER 6 Understanding Inheritance and Polymorphism . 167 ■CHAPTER 7 Understanding Structured Exception Handling . 201 ■CHAPTER 8 Understanding Object Lifetime . 225 PART 4 ■ ■ ■ Advanced Object-Oriented Programming Techniques ■CHAPTER 9 Working with Interfaces and Collections . 245 ■CHAPTER 10 Callback Interfaces, Delegates, and Events . 281 ■CHAPTER 11 Advanced VB 2005 Programming Constructs. 309 ■CHAPTER 12 Understanding Generics and Nullable Data Types . 337 v 5785ch00FM.qxd 3/31/06 3:31 PM Page vi PART 5 ■ ■ ■ Programming with .NET Assemblies ■CHAPTER 13 Introducing .NET Assemblies. 363 ■CHAPTER 14 Type Reflection, Late Binding, and Attribute-based Programming. 407 ■CHAPTER 15 Processes, AppDomains, Contexts, and CLR Hosts. 441 ■CHAPTER 16 Building Multithreaded Applications . 463 ■CHAPTER 17 COM and .NET Interoperability . 493 PART 6 ■ ■ ■ Exploring the .NET Base Class Libraries ■CHAPTER 18 The System.IO Namespace . 527 ■CHAPTER 19 Understanding Object Serialization. 555 ■CHAPTER 20 The .NET Remoting Layer. 573 ■CHAPTER 21 Building a Better Window with System.Windows.Forms . 611 ■CHAPTER 22 Rendering Graphical Data with GDI+ . 655 ■CHAPTER 23 Programming with Windows Forms Controls . 707 ■CHAPTER 24 Database Access with ADO.NET . 767 PART 7 ■ ■ ■ Web Applications and XML Web Services ■CHAPTER 25 Building ASP.NET 2.0 Web Pages . 837 ■CHAPTER 26 ASP.NET 2.0 Web Controls, Themes, and Master Pages . 883 ■CHAPTER 27 ASP.NET 2.0 State Management Techniques . 919 ■CHAPTER 28 Understanding XML Web Services. 955 ■INDEX . 991 vi 5785ch00FM.qxd 3/31/06 3:31 PM Page vii Contents About the Author . xxxiii About the Technical Reviewer. xxxv Acknowledgments . xxxvii Introduction . xxxix PART 1 ■ ■ ■ Introducing Visual Basic 2005 and the .NET Platform ■CHAPTER 1 The Philosophy of .NET . 3 Understanding the Previous State of Affairs . 3 Life As a C/Win32 API Programmer . 3 Life As a C++/MFC Programmer . 4 Life As a Visual Basic 6.0 Programmer . 4 Life As a Java/J2EE Programmer. 4 Life As a COM Programmer . 5 Life As a Windows DNA Programmer. 5 The .NET Solution. 6 Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS) . 6 The Role of the Base Class Libraries . 7 What Visual Basic 2005 Brings to the Table . 7 Additional .NET-Aware Programming Languages. 8 Life in a Multilanguage World . 9 An Overview of .NET Assemblies . 10 Single-File and Multifile Assemblies . 11 The Role of the Common Intermediate Language . 12 Benefits of CIL . 14 Compiling CIL to Platform-Specific Instructions . 14 The Role of .NET Type Metadata . 14 The Role of the Assembly Manifest . 15 Understanding the Common Type System. 16 CTS Class Types . 16 CTS Structure Types . 16 CTS Interface Types. 17 CTS Enumeration Types . 17 vii 5785ch00FM.qxd 3/31/06 3:31 PM Page viii viii ■CONTENTS CTS Delegate Types. 17 CTS Type Members . 18 Intrinsic CTS Data Types . 18 Understanding the Common Language Specification . 19 Ensuring CLS Compliance . 20 Understanding the Common Language Runtime . 20 The Assembly/Namespace/Type Distinction . 22 Accessing a Namespace Programmatically . ..