Contents Chapter 2: Introducing Visual Basic 2005 and visual Studio 2005 19 Visual Studio. NET-Startup Visua| Studio∴NET 21 The solution Explorer My Project References Assembly Information Screen The New Code window The Properties window Dynamic Help Working with Visual Basic 2005 Form Properties Set in Code Enhancing the Sample Application 34 Adding a Control and Event Handler Customizing the Code Build Configurations Building Application Useful features of visual studio 46 The Task list The Server Explorer Recording and Using Macros in visual Studio 2005 Summary Chapter 3: Variables and Type 51 Differences of value and Reference Types Value Types( structures 54 Primitive Type Explicit Conversions 63 Compiler Options Performing Explicit Conversions Reference Types(classes) The String Class The DBNull Class and IsDBNullo Function Arrays Collections Parameter Passing 78
x Contents Chapter 2: Introducing Visual Basic 2005 and Visual Studio 2005 19 Visual Studio .NET — Startup 20 Visual Studio .NET 21 The Solution Explorer 22 My Project 23 References 24 Assembly Information Screen 25 The New Code Window 26 The Properties Window 29 Dynamic Help 30 Working with Visual Basic 2005 31 Form Properties Set in Code 32 Enhancing the Sample Application 34 Adding a Control and Event Handler 34 Customizing the Code 35 Build Configurations 40 Building Applications 43 Useful Features of Visual Studio 46 The Task List 46 The Command Window 47 The Server Explorer 47 Recording and Using Macros in Visual Studio 2005 49 Summary 50 Chapter 3: Variables and Type 51 Differences of Value and Reference Types 52 Value Types (Structures) 54 Primitive Types 54 Explicit Conversions 63 Compiler Options 64 Performing Explicit Conversions 66 Reference Types (Classes) 68 The Object Class 68 The String Class 70 The DBNull Class and IsDBNull() Function 72 Arrays 73 Collections 76 Parameter Passing 78 Boxing 79 02_575368 ftoc.qxd 10/7/05 10:47 PM Page x
Contents Retired Keywords and Methods Elements of visual basic 6.0 Removed in. net Summary Chapter 4: object Syntax Introduction object-Oriented Terminology Objects, Classes, and Instances Composition of an object Working with Objects 88 Object Declaration and Instantiation Object References Dereferencing Objects Early versus Late Binding Creating Classes Creating Ba Constructor Methods 114 ermination and cleanup 115 Advanced Concepts 116 Overloading Methods 116 Overloading Constructor Methods 119 Shared Methods. Variables, and Events Operator Overloading 125 Summary 134 Chapter 5: Inheritance and Interfaces 137 Inheritance 138 Implementing Inheritance Multiple Interfaces 187 Object Interfaces 187 Secondary Interface 189 Summary 19 Chapter 6: The Common Language Runtime 197 Elements of a. NET Application 19 Assemblies 199 ypes
xi Contents Retired Keywords and Methods 80 Elements of Visual Basic 6.0 Removed in .NET 80 Summary 81 Chapter 4: Object Syntax Introduction 83 Object-Oriented Terminology 84 Objects, Classes, and Instances 84 Composition of an Object 85 Working with Objects 88 Object Declaration and Instantiation 88 Object References 90 Dereferencing Objects 90 Early versus Late Binding 90 Creating Classes 94 Creating Basic Classes 94 Constructor Methods 114 Termination and Cleanup 115 Advanced Concepts 116 Overloading Methods 116 Overloading Constructor Methods 119 Shared Methods, Variables, and Events 120 Operator Overloading 125 Delegates 128 Classes versus Components 133 Summary 134 Chapter 5: Inheritance and Interfaces 137 Inheritance 138 Implementing Inheritance 140 Multiple Interfaces 187 Object Interfaces 187 Secondary Interfaces 189 Summary 195 Chapter 6: The Common Language Runtime 197 Elements of a .NET Application 198 Modules 198 Assemblies 199 Types 200 02_575368 ftoc.qxd 10/7/05 10:47 PM Page xi
Contents Versioning and Deployment 201 Better Support for Versioning 201 Better Deployment 202 Cross-Language Integration 203 The Common Type System Metadata 204 Better Support for Metadata The Reflection APl IL Disassembler Memory Management 210 Traditional"Garbage Collection Faster Memory Allocation for Objects 218 Garbage Collector Opt 220 222 Chapter z, applying objects and components 223 Abstraction 22 Encapsulation 227 Polymorphi Implementing Polymorphism 230 Inheritance 241 When to Use inheritance Inheritance and Multiple Interfaces 246 to go? Fragile Base Class Issue 254 Summary Chapter 8: Generics 259 Using Generics Generic Types Generic Methods 265 Creating Generics 267 Generic Types 267 Generic Methods Constraints 276 Generics and Late binding 280
xii Contents Versioning and Deployment 201 Better Support for Versioning 201 Better Deployment 202 Cross-Language Integration 203 The Common Type System 203 Metadata 204 Better Support for Metadata 205 Attributes 206 The Reflection API 208 IL Disassembler 209 Memory Management 210 Traditional “Garbage Collection” 211 Faster Memory Allocation for Objects 218 Garbage Collector Optimizations 220 Summary 222 Chapter 7: Applying Objects and Components 223 Abstraction 223 Encapsulation 227 Polymorphism 230 Method Signatures 230 Implementing Polymorphism 230 Inheritance 241 When to Use Inheritance 242 Inheritance and Multiple Interfaces 246 How Deep to Go? 252 Fragile Base Class Issue 254 Summary 257 Chapter 8: Generics 259 Using Generics 260 Generic Types 261 Generic Methods 265 Creating Generics 267 Generic Types 267 Generic Methods 275 Constraints 276 Generics and Late Binding 280 Summary 281 02_575368 ftoc.qxd 10/7/05 10:47 PM Page xii
Contents Chapter 9: Namespaces 28 What Is a Namespace? 284 Namespaces and References Common Namespaces 289 Importing and Aliasing Namespaces 291 porting Namespaces eferencing Namespaces in ASPNE Creating Your Own Namespaces 295 298 My Application My Computer My Resources My Web Services Summary 309 Chapter 10; Exception handling and debugging. 311 A Brief Review of Error Handling in VB6 Exceptions in NET 314 Important Properties and Methods of an Exception 314 How Exceptions Differ from the Err Object in VB6 Structured- Exception-Handling Keywords in VB. NET 315 The Try, Catch, and Finally Keyword 316 The Throw Keyword 318 Throwing a New Exception 319 The Exit Try statement Nested Try Structures The Message Property The InnerException and Targetsite Properties Interoperability with vb6-style Error Handling 328 Error Logging 329 Writing to Trace Files Analyzing Problems and Measuring Performance via the Trace Class 335
xiii Contents Chapter 9: Namespaces 283 What Is a Namespace? 284 Namespaces and References 287 Common Namespaces 289 Importing and Aliasing Namespaces 291 Importing Namespaces 292 Referencing Namespaces in ASP.NET 293 Aliasing Namespaces 294 Creating Your Own Namespaces 295 My 298 My.Application 299 My.Computer 303 My.Forms 307 My.Resources 308 My.User 308 My.WebServices 308 Summary 309 Chapter 10: Exception Handling and Debugging 311 A Brief Review of Error Handling in VB6 312 Exceptions in .NET 314 Important Properties and Methods of an Exception 314 How Exceptions Differ from the Err Object in VB6 315 Structured-Exception-Handling Keywords in VB.NET 315 The Try, Catch, and Finally Keywords 316 The Throw Keyword 318 Throwing a New Exception 319 The Exit Try Statement 320 Nested Try Structures 321 The Message Property 323 The InnerException and TargetSite Properties 323 Interoperability with VB6-Style Error Handling 328 Error Logging 329 Writing to Trace Files 333 Analyzing Problems and Measuring Performance via the Trace Class 335 Summary 338 02_575368 ftoc.qxd 10/7/05 10:47 PM Page xiii
Contents Chapter 11: Data Access with adO. NeT 2.0 341 ADO. NET 2.0 Architecture Enhancements 34 ADO. NET Components NET Data Providers 344 Connection Object Command object 345 Using Stored Procedures with Command Objects 350 Executing Commands Asynchronously 352 SQL Server. NET Data Provider OLE DB. NET Data Provider 353 The DataSet Component 359 DataTable collection 359 taRelation Collection ExtendedProperties Creating and Using Data Set Objects ADO. NET DataTable Objects ADO. NeT 2.0 Enhancements to the data set and dataTable Working with the Common Provider Model 366 Connection Pooling Enhancements in ADO. NET 2.0 369 Building a Data Access Component 369 Constructors Properties 371 Stored Procedure xml structure Methods 373 Using Data Set Objects to Bind to Data Grids Summary Chapter 12: Using XML in Visual Basic 2005 389 An introduction to xml 391 XML Serialization 392 Source Code Style Attributes System. Xml Document Support 399 XML Stream-style Parsers 399 Writing an XML Stream Reading an XML Stream 405 Using the Memory Stream Object 414 Document object Model(DOM)
xiv Contents Chapter 11: Data Access with ADO.NET 2.0 341 ADO.NET 2.0 Architecture Enhancements 342 ADO.NET Components 343 .NET Data Providers 344 Connection Object 344 Command Object 345 Using Stored Procedures with Command Objects 346 DataReader Object 350 Executing Commands Asynchronously 352 DataAdapter Objects 354 SQL Server .NET Data Provider 358 OLE DB .NET Data Provider 359 The DataSet Component 359 DataTableCollection 359 DataRelationCollection 360 ExtendedProperties 360 Creating and Using DataSet Objects 361 ADO.NET DataTable Objects 363 ADO.NET 2.0 Enhancements to the DataSet and DataTable 364 Working with the Common Provider Model 366 Connection Pooling Enhancements in ADO.NET 2.0 369 Building a Data Access Component 369 Constructors 370 Properties 371 Stored Procedure XML Structure 372 Methods 373 Using DataSet Objects to Bind to DataGrids 385 Summary 388 Chapter 12: Using XML in Visual Basic 2005 389 An Introduction to XML 391 XML Serialization 392 Source Code Style Attributes 397 System.Xml Document Support 399 XML Stream-Style Parsers 399 Writing an XML Stream 400 Reading an XML Stream 405 Using the MemoryStream Object 414 Document Object Model (DOM) 418 02_575368 ftoc.qxd 10/7/05 10:47 PM Page xiv