Dedication............................................................................................................iii
Acknowledgments............................................................................................ xiii
About This Book .............................................................................................. xv
Chapter 1 Introduction ........................................................................ 1
Visual Basic Then and Now .............................................................................. 1
The Versions of Visual Basic ........................................................................ 2
The .NET Mentality Shift ................................................................................ 3
The Common Language Runtime ...................................................................... 4
Completely Object Oriented ............................................................................... 5
Automatic Garbage Collection: Fewer Memory Leaks ..................................... 6
Structured Exception Handling ..................................................................... 6
True Multithreading ........................................................................................... 6
Why You Will Need To Learn a Whole Lot of New Concepts
to Use VB .NET ............................................................................................... 7
Should You Use C# and Not Bother with VB .NET? ................................ 9
Chapter 2 The VB .NET IDE: Visual Studio .NET ........... 11
Getting Started .................................................................................................. 12
Creating a New Solution ................................................................................... 13
A Tour of the Main Windows in the IDE .................................................. 17
The Editor ........................................................................................................... 19
The Solution Explorer ........................................................................................ 24
Properties Window ............................................................................................ 25
References and the Reference Window ........................................................... 26
Output Window and Command Window ........................................................ 27
Working with a Solution ................................................................................ 28
Adding Projects to a Solution ............................................................................ 33
Compiling ............................................................................................................... 34
Multiple Compilations ...................................................................................... 36
Build Options ..................................................................................................... 38
Debug vs. Release Versions ............................................................................... 39
Output Files ........................................................................................................ 40
Contents
vi
Debugging in VB .NET ........................................................................................40
New Debugger Features .....................................................................................41
Chapter 3 Expressions, Operators,
and Control Flow .............................................................47
Console Applications ........................................................................................48
Statements in VB .NET ......................................................................................51
Comments ..................................................................................................................52
Variables and Variable Assignments .........................................................52
Literals and Their Associated Data Types ............................................54
Non-Numeric Literals ........................................................................................58
Declaring Variables ..........................................................................................59
Conversion between Values of Different Types ...............................................61
Strings ....................................................................................................................64
String Functions .................................................................................................65
Formatting Data .................................................................................................68
Arithmetic Operators ........................................................................................69
Parentheses and Precedence .............................................................................72
Math Functions and Math Constants ...............................................................73
Constants ................................................................................................................75
Repeating Operations—Loops ...........................................................................75
Determinate Loops .............................................................................................75
Indeterminate Loops ..........................................................................................77
Conditionals—Making Decisions ....................................................................79
Scoping Changes ................................................................................................80
Short Circuiting ..................................................................................................81
Select Case ...........................................................................................................81
The GoTo ..................................................................................................................82
The Logical Operators on the Bit Level ................................................83
Arrays ......................................................................................................................84
The For-Each Construct ....................................................................................86
Arrays with More than One Dimension ............................................................87
Procedures: User-Defined Functions and Subs .....................................87
Functions ............................................................................................................88
Sub Procedures ...................................................................................................90
Using Arrays with Functions and Procedures ..................................................92
Procedures with a Variable or Optional Number of Arguments ....................93
Recursion ................................................................................................................94
Contents
vii
Chapter 4 Classes and Objects (with a Short
Introduction to Object-Oriented
Programming) ...................................................................... 97
Introduction to OOP ......................................................................................... 98
Classes As (Smart) User-Defined Types ........................................................... 99
The Vocabulary of OOP ................................................................................... 101
The Relationships between Classes in Your Programs ................................. 101
How to Objectify Your Programs ............................................................... 107
What about Individual Objects? ............................................................... 109
Advantages to OOP ............................................................................................ 110
Creating Object Instances in VB .NET .................................................. 111
More on Constructors: Parameterized Constructors ................................... 114
Example: The String Class .............................................................................. 115
Example: The StringBuilder Class .................................................................. 115
Namespaces ........................................................................................................... 120
Imports ............................................................................................................. 120
Help and the (Vast) .NET Framework ...................................................... 124
Example: The Framework Collection Classes ............................................... 127
More on Object Variables ............................................................................ 134
Is and Nothing .................................................................................................. 136
TypeName and TypeOf ......................................................................................... 137
Subtleties of Passing Object Variables by Value ............................................ 138
Building Your Own Classes .......................................................................... 140
Overloading Class Members ........................................................................... 144
More on Constructors ..................................................................................... 147
More on Properties .......................................................................................... 148
Scope of Variables ............................................................................................ 150
Nested Classes .................................................................................................. 152
Shared Data and Shared Members Inside Classes .............................. 155
Shared Members .............................................................................................. 157
The Object Life Cycle ................................................................................... 158
Object Death .................................................................................................... 160
Value Types ......................................................................................................... 161
Enums ............................................................................................................... 163
Structure Types ................................................................................................ 165
Namespaces for Classes You Create ......................................................... 168
The Class View Window ................................................................................... 169
Debugging Object-Based Programs ............................................................. 170
Summary ................................................................................................................. 175
Contents
viii
Chapter 5 Inheritance and Interfaces .................................177
Inheritance Basics ..........................................................................................178
Getting Started with Inheritance .....................................................................180
Overriding Properties and Methods ...............................................................184
Abstract Base Classes .......................................................................................195
Object: The Ultimate Base Class ..............................................................201
The Most Useful Members of Object ..............................................................202
The Fragile Base Class Problem: Versioning ......................................209
Overview of Interfaces .................................................................................215
Mechanics of Implementing an Interface ......................................................217
When to Use Interfaces, When To Use Inheritance? .........................222
Important Interfaces in the .NET Framework ......................................222
ICloneable .........................................................................................................223
IDisposable .......................................................................................................225
Collections .........................................................................................................225
For Each and IEnumerable ..............................................................................226
Chapter 6 Event Handling and Delegates ............................237
Event Handling from an OOP Point of View ..........................................237
What Goes into the Functions Called by Events? ..........................................239
Basic Event Raising ........................................................................................241
Hooking Up the Listener Objects to Event Source Objects ..........................243
Building Your Own Event Classes ...................................................................247
Dynamic Event Handling ................................................................................249
Handling Events in an Inheritance Chain ......................................................253
Delegates ..............................................................................................................254
Building Up a Delegate ....................................................................................255
A More Realistic Example: Special Sorting .....................................................257
Delegates and Events .......................................................................................264
Chapter 7 Error Handling the VB .NET Way:
Living with Exceptions ...........................................265
Error Checking vs. Exception Handling .................................................266
First Steps in Exception Handling ...................................................................267
Analyzing the Exception ..................................................................................269
Multiple Catch Clauses ....................................................................................269
Throwing Exceptions ........................................................................................272
Exceptions in the Food Chain .........................................................................275
And Finally…Finally Blocks .........................................................................277
Some Tips for Using Exceptions ................................................................278
Contents
ix
Chapter 8 Windows Forms, Drawing,
and Printing....................................................................... 279
First, Some History ....................................................................................... 280
Form Designer Basics ..................................................................................... 281
Keeping Things in Proportion: The Anchor and Dock Properties ............... 284
The Tab Order Menu ....................................................................................... 287
Returning to a Simple Program ................................................................. 287
More Form Properties ..................................................................................... 292
Menu Controls and the New Visual Studio Menu Editor ................. 294
Context Menus ................................................................................................. 297
MDI Forms ....................................................................................................... 298
ColorDialog ...................................................................................................... 301
FontDialog ........................................................................................................ 302
FileDialogs ........................................................................................................ 302
Adding Controls at Run Time ......................................................................... 303
Form Inheritance: AKA Visual Inheritance ......................................... 305
Building Custom Controls through Control Inheritance ............... 306
Overriding an Event ......................................................................................... 306
The Inheritance Chains in the
System.Windows.Forms Assembly .......................................................... 313
Basic Control Class Functionality .................................................................. 316
Graphics: Using GDI+ ..................................................................................... 318
Simple Drawing ............................................................................................... 320
Drawing Text .................................................................................................... 321
Printing ............................................................................................................... 325
Chapter 9 Input/Output .................................................................... 333
Directories and Files ................................................................................... 334
The Path Class .................................................................................................. 335
The Directory Class .......................................................................................... 336
The File Class ................................................................................................... 338
The DirectoryInfo and FileInfo Classes .............................................. 340
Working Recursively through a Directory Tree ............................................. 341
The Most Useful Members of the FileSystemInfo, FileInfo,
and DirectoryInfo Classes ...................................................................... 344
Streams ................................................................................................................. 347
Writing to Files: File Streams .......................................................................... 350
Getting Binary Data into and out of Streams:
BinaryReader and BinaryWriter ................................................................ 355
TextReader, TextWriter, and Their Derived Classes ....................................... 358
Object Streams: Persisting Objects ................................................................ 361
Simple Serialization ......................................................................................... 362
Contents
x
Simple Deserialization .....................................................................................364
Network Streams ..............................................................................................370
Writing a File System Monitor ..................................................................375
Going Further with File Monitoring ...............................................................378
Chapter 10 Multithreading ................................................................379
Getting Started with Multithreading .....................................................380
The Mechanics of Thread Creation ................................................................383
Join .....................................................................................................................388
Thread Names, CurrentThread, and ThreadState .........................................389
The Threads Window .......................................................................................390
Putting a Thread to Sleep .................................................................................391
Ending or Interrupting a Thread .....................................................................392
A More Serious Example: Screen Scraping Redux .........................................394
The Big Danger: Shared Data ......................................................................397
The Solution: Synchronization ........................................................................401
More on SyncLock and the Monitor Class .....................................................403
Deadlock: the Danger of Synchronization .....................................................404
Sharing Data as It Is Produced ........................................................................410
Multithreading a GUI Program ....................................................................415
Chapter 11 A Brief Introduction to Database Access
with VB .NET .....................................................................423
Why ADO .NET Is Not ADO++ ...........................................................................423
Disconnected Data Sets: The New Way to Use Databases ................424
The Classes in System.Data.DLL ................................................................425
System.Data.OleDb ..........................................................................................425
System.Data.SqlClient .....................................................................................429
Calling a Stored Procedure .........................................................................430
A More Complete VB .NET Database Application .................................431
Chapter 12 A Brief Overview of ASP .NET ............................443
Some History .......................................................................................................443
A Simple ASP .NET Web Application .........................................................444
What Gets Sent to the Client? ..........................................................................448
The Web.config File ..........................................................................................451
A Simple Web Service ......................................................................................455
Client-Side Use of a Web Service ....................................................................458
Contents
xi
Chapter 13 .NET Assemblies, Deployment,
and COM Interop............................................................... 463
How COM Works .................................................................................................... 464
.NET Assemblies ................................................................................................ 465
The Manifest .................................................................................................... 467
Drilling Down into a Manifest ........................................................................ 469
Shared Assemblies and the GAC ................................................................. 471
Adding and Removing Assemblies from the GAC ......................................... 473
Strong Names = Shared Names ...................................................................... 473
Generating a Key Pair ...................................................................................... 474
Signing an Assembly ........................................................................................ 476
COM Interoperability and Native DLL Function Calls ................... 476
DLL Function Calls .......................................................................................... 477
No comments:
Post a Comment
This is Good Computer Information Blog.they will give
best information about computer.