Tải bản đầy đủ (.pdf) (782 trang)

Programming Visual Basic 2008 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.35 MB, 782 trang )

www.it-ebooks.info
www.it-ebooks.info
Programming Visual Basic 2008
www.it-ebooks.info
Other Microsoft .NET resources from O’Reilly
Related titles
ADO.NET 3.5 Cookbook

Building a Web 2.0 Portal
with ASP.NET 3.5
C# Cookbook

C# 3.0 in a Nutshell
C# 3.0 Pocket Reference
Learning ASP.NET 3.5
Programming ASP.NET 3.5
Programming ASP.NET AJAX
Visual Basic 2005 Cookbook

.NET Books
Resource Center
dotnet.oreilly.com is a complete catalog of O’Reilly’s books on
.NET and related technologies, including sample chapters and
code examples.
ONDotnet.com provides independent coverage of fundamental,
interoperable, and emerging Microsoft .NET programming and
web services technologies.
Conferences
O’Reilly brings diverse innovators together to nurture the ideas
that spark revolutionary industries. We specialize in document-
ing the latest tools and systems, translating the innovator’s


knowledge into useful skills for those in the trenches. Visit
conferences.oreilly.com for our upcoming events.
Safari Bookshelf (safari.oreilly.com) is the premier online refer-
ence library for programmers and IT professionals. Conduct
searches across more than 1,000 books. Subscribers can zero in
on answers to time-critical questions in a matter of seconds.
Read the books on your Bookshelf from cover to cover or sim-
ply flip to the page you need. Try it today for free.
www.it-ebooks.info
Programming
Visual Basic 2008
Tim Patrick
Beijing

Cambridge

Farnham

Köln

Sebastopol

Taipei

Tokyo
www.it-ebooks.info
Programming Visual Basic 2008
by Tim Patrick
Copyright © 2008 Tim Patrick. All rights reserved.
Printed in the United States of America.

Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
Editor:
John Osborn
Production Editor:
Rachel Monaghan
Copyeditor:
Audrey Doyle
Proofreader:
Rachel Monaghan
Indexer:
Ellen Troutman Zaig
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrator:
Robert Romano
Printing History:
May 2008: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Programming Visual Basic 2008, the image of a bufflehead duck, and related trade
dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information

contained herein.
This book uses RepKover

, a durable and flexible lay-flat binding.
ISBN: 978-0-596-51843-1
[M]
www.it-ebooks.info
To Maki, my lovely wife
www.it-ebooks.info
www.it-ebooks.info
vii
Table of Contents
Preface
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xv
1. Introducing .NET
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Before .NET 1
Back to Introducing .NET 2
The .NET Object 3
The Parts of the .NET Framework 7
From Source Code to EXE 16
What About Visual Studio and Visual Basic? 17
Visual Studio 2008 18
Summary 22
Project 23
2. Introducing Visual Basic
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30

The History of the Visual Basic Revolution 30
Visual Basic from the Inside Out 32
The Basics of Logic and Data 32
Data Types and Variables 35
Intermission 44
Comments 44
Option Statements 45
Basic Operators 47
Using Functions and Subroutines 49
Conditions 50
Loops 54
Creating Your Own Procedures 57
Other Flow Control Features 61
www.it-ebooks.info
viii | Table of Contents
Events and Event Handlers 64
Namespaces 66
The My Namespace 69
Summary 70
Project 70
3. Introducing the Project
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
75
The Library Project 76
The Needs of the Users 79
The Life of a Project 83
Summary 90
Project 90
4. Designing the Database
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95
Relational Databases 95
SQL Server 2005 98
SQL 100
Using Databases in Visual Basic 107
Documenting the Database 108
Summary 109
Project 109
5. .NET Assemblies
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
126
What Is an Assembly? 126
What’s Inside an Assembly? 128
Assemblies and Applications 131
The My Namespace and Assemblies 132
Directives and Assemblies 134
Summary 136
Project 137
6. Data and Data Types
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
151
The Nature of Computer Data 151
Data in .NET 153
Visual Basic Data Types 158
Literals 159
Constants 160
www.it-ebooks.info
Table of Contents | ix
Enumerations 161
Variables 162

Variable and Constant Naming Conventions 165
Local Type Inference 166
Operators 167
Static Variables 172
Arrays 172
Nullable Types 175
Common Visual Basic Functions 176
Summary 181
Project 182
7. Windows Forms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
187
Inside a Windows Application 187
Windows in .NET 191
Making Forms Useful 210
Summary 212
Project 212
8. Classes and Inheritance
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
219
Object-Oriented Programming Concepts 219
OOP in Visual Basic and .NET 224
Related Issues 241
Summary 244
Project 244
9. Functional Programming
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
253
Lambda Expressions 253
Object Initializers 259

Error Handling in Visual Basic 260
The Nature of Errors in Visual Basic 260
Unstructured Error Handling 263
Structured Error Handling 265
Unhandled Errors 267
Managing Errors 269
Summary 273
Project 274
www.it-ebooks.info
x | Table of Contents
10. ADO.NET
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
277
What Is ADO.NET? 278
Overview of ADO.NET 279
Data Sets Versus No Data Sets 282
Connecting to SQL Server with Visual Studio 284
Interacting with SQL Server in Code 289
Database Transactions 292
ADO.NET Entity Framework 293
Summary 294
Project 294
11. Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
303
Security Features in .NET 304
Cryptography and Encryption 304
Encryption in .NET 306
Other Security Features 311
Summary 312

Project 312
12. Overloads and Extensions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
330
What Is Operator Overloading? 330
What Can You Overload? 332
Other Operator Overloading Issues 338
Extension Methods 340
Summary 342
Project 342
13. XML
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
361
What Is XML? 361
The XML Rule 364
XML Content 365
Using XML in .NET: The Old Way 371
Using XML in .NET: The New Way 375
Summary 378
Project 379
www.it-ebooks.info
Table of Contents | xi
14. Application Settings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
392
A Short History of Settings 392
Settings in Visual Basic 2008 394
Summary 400
Project 401
15. Files and Directories

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
416
Traditional Visual Basic File Management 417
Manipulating Files Through Streams 418
File Management with the My Namespace 424
Summary 427
Project 428
16. Generics
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
433
What Are Generics? 433
Variations of Generic Declaration 436
Summary 442
Project 442
17. LINQ
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
448
What Is LINQ? 448
Anonymous Types 450
LINQ to Objects 451
Basic Query Expressions 453
Converting Results to Other Forms 459
Aggregate Queries 459
Advanced Query Expressions 460
LINQ to XML 461
LINQ for ADO.NET-Related Data 463
Deferred Execution 468
Summary 469
Project 470
18. User Interface

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
486
Overview of GDI+ 487
Selecting a Canvas 488
Choosing Pens and Brushes 490
www.it-ebooks.info
xii | Table of Contents
Flowing Text from the Font 493
Imagining Images 497
Exposing Your True Artist 499
Paths: Drawings on Macro-Vision 501
Keeping It Regional 502
Twisting and Turning with Transformations 503
Enhancing Controls Through Owner Draw 505
Windows Presentation Foundation 507
Enhancing Classes with Attributes 510
Summary 511
Project 511
19. Localization and Globalization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
526
Defining Globalization and Localization 526
Resource Files 527
The My.Resources Object 529
Localizing Forms Within Visual Studio 531
Adding Resources Outside Visual Studio 534
Manually Compiling Resources 535
Other Localization Features 537
Summary 538
Project 539

20. Printing
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
552
Printing in Windows 553
Printing in .NET 554
Printing a Document 557
Print Preview 559
Counting and Numbering Pages 561
Printing in “Raw” Mode 563
Summary 564
Project 564
21. Reporting
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
581
Report Options in .NET 581
Using Reporting Controls in .NET 584
Summary 597
Project 597
www.it-ebooks.info
Table of Contents | xiii
22. Licensing Your Application
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
611
Software Licensing Options 611
License Agreements 615
Obfuscation 616
The Library Licensing System 618
Summary 621
Project 622
23. Web Development

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
642
How the Internet Works 642
Programming the Internet 644
ASP.NET Features 645
Trying Out ASP.NET 646
More About Events 653
State and View State 654
Data Validation 655
Database Integration 657
Windows Communication Foundation 658
Summary 663
Project 663
24. Adding Online Help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
672
Windows Online Help Options 672
Designing HTML Help 674
Accessing HTML Help 680
Summary 683
Project 683
25. Deployment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
689
What’s Involved in Deployment? 689
Deployment Methods Within Visual Studio 690
Summary 700
Project 700
26. Project Complete
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

711
The Library Project 711
Visual Basic Flexibility 714
The Programming Mindset 716
Summary 717
www.it-ebooks.info
xiv | Table of Contents
A. Installing the Software
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
719
B. Software License Agreement
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
722
Index
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
725
www.it-ebooks.info
xv
Preface1
Welcome to Programming Visual Basic 2008! I know you’re going to enjoy it; I’ve
read it five times already. You’re probably anxious to get to Chapter 1, but I recom-
mend you read this preface to make sure you paid for the right book.
Who Is Reading This Book?
Writing a book is a lot like writing a Visual Basic application. Well, except for the
part about finding a publisher, and working with an editor. And then there’s that
pesky rule about correct spelling. Come to think of it, they’re really quite different.
But in one way, books and programs are similar: both are written to meet the needs
of the user. When writing software applications, the user’s needs drive the organiza-
tion and features of the final program. When writing a book, like the one you’re
looking at now, the needs of the user—that’s you, the reader—drive the organiza-

tion and features of the final text.
So it was with you in mind that I set out to write this book. Oh, there’s the fame and
the prestige, but it’s really about you. You, the person who seeks to understand
Visual Basic and the .NET Framework on which it is built. When I thought about
you and your needs, I came up with these ideas:
You might know how to program, but maybe not
In the programming world, there are four types of people: (1) those who
already program joyfully; (2) those who don’t program, but will learn it and
love it; (3) those who don’t program, but will learn it and struggle with it; and
(4) those who should return this book immediately to the bookstore. If you are
in one of the first three groups, this book is definitely for you. I believe that anyone
who can break down a task into its basic step-by-step instructions can successfully
program in Visual Basic. If you are unsure about your ability to quantify tasks in
this way, you might want to start out with a book on basic programming concepts.
www.it-ebooks.info
xvi
|
Preface
You might know how to program in Visual Basic or .NET, but maybe not
And that’s OK, because this book will teach you. Most of the chapters introduce
important topics in Visual Basic and .NET development, such as object-oriented
programming concepts, or using the different types of variables available to you,
or interacting with a database. If you already know how to use Visual Basic 6 or
earlier, that’s great, but it’s not a prerequisite.
You want to write programs
Most programming books teach you to write code in 10-line increments. At least
that’s what’s scattered throughout their pages. I’ve put some of those “code
snippets” in this book. But I spend my days writing real programs, not 10-line
sample programs. If you want to write whole programs, you should learn using
whole programs. That’s why I also put a program in my book—a whole pro-

gram. Over the next several hundred pages, I will develop a real program—a
database for a small library—and you will write it with me.
I put all of these ideas into 26 easy-to-read chapters, and had O’Reilly Media glue the
pages together for your convenience. When you reach the index, you will have
learned how to write complete programs in Visual Basic and .NET. It will be a pro-
gramming adventure, so let’s get started!
What’s in This Book?
Since we are going to be spending a lot of time together, you probably want to know
something about me. Well, my name is Tim Patrick, and for many years I lived just
up the street from the big Microsoft campus. I’ve been writing programs for 25 years,
and these days I write custom database-oriented Visual Basic applications for small to
medium-size businesses. And I’m not alone. Most Visual Basic developers write
business-level software. If that’s what you do, or plan to do, you’re in great company.
As you move through the pages of this book, you will read about the major .NET
and Visual Basic activities that drive the development of business-level and general con-
sumer applications. If you plan to do some other type of programming, such as game
development, this book will be somewhat helpful, but I don’t talk about advanced or
specialized features such as interactive 3D models or geometric transformations.
Each chapter discusses a major programming topic, and then follows it up with a
practical implementation of that topic: the creation of the Library database program.
I don’t show every line of code in the book; if I did, the book would weigh 53
pounds and cost $254.38, plus tax. To get every line of source code, you’ll have to
download the accompanying source code from the book’s web site. The code and
the book’s text are united in one purpose: to train you in the skilled use of Visual
Basic on the .NET platform so that you can develop the highest-quality applications
possible. The text and the source code both include valuable resources that you can
use every day in your programming life.
www.it-ebooks.info
Preface
|

xvii
What’s in the Software Download?
You’re going to like the download. It contains all the source code for the Library
database project. What’s cool is that when you install the source code examples,
they become part of Visual Studio. Once they are installed, you can create a new
chapter-specific project right from the File
➝ New Project menu in Visual Studio.
Appendix A has all of the download and installation details.
I wrote the project code using Visual Basic 2008 Professional Edition. Some portions
may not be compatible with earlier .NET versions of the language. None of it is com-
patible with Visual Basic 6.0 or earlier, so don’t even bother trying. The source code
will work with any edition of Visual Basic 2008, including the Express Edition.
The source code also uses SQL Server 2005 for its database storage. You can use
any edition of SQL Server 2005, including the Express Edition. Chapter 4 intro-
duces databases and SQL Server 2005. If you will be using the database in an IT
department-controlled network environment, you may need to talk with your IT
department representative about installing the sample database. The SQL code I use
is pretty vanilla, so it should work on previous versions of SQL Server, and you could
easily adjust it to work with Oracle, DB2, Microsoft Access, or other common data-
base engines. You can also use the upcoming SQL Server 2008 if you have it available.
You can use the downloadable source code for your own projects, but please give
credit where credit is due. There is a license agreement associated with the code (see
Appendix B), so please don’t go selling the software as your own work. Just to be on
the safe side, I’ve added a few hard-to-find bugs. Just kidding! (No, I’m not!)
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, filenames, and file extensions.
Constant width
Indicates computer coding in a broad sense. This includes all Visual Basic source

code, HTML content, XML content, commands, options, source code from
other languages, and content generated by Visual Studio tools.
Constant width bold
Indicates commands or other text that the user should type literally. Also used to
highlight a particular section of code.
Constant width italics
Indicates text that should be replaced with user-supplied values or values deter-
mined by context.
www.it-ebooks.info
xviii
|
Preface
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this
book in your programs and documentation. You do not need to contact the publisher or
me for permission unless you’re reproducing a significant portion of the code. For
example, writing a program that uses several chunks of code from this book does not
require permission. Selling or distributing a CD-ROM of examples from O’Reilly books
does require permission. Answering a question by citing this book and quoting exam-
ple code does not require permission. Incorporating a significant amount of example
code from this book into your product’s documentation requires that you abide by the
terms of the software license agreement found in Appendix B.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Programming Visual Basic 2008,by
Tim Patrick. Copyright 2008 Tim Patrick, 978-0-596-51843-1.”
If you feel your use of code examples falls outside fair use or the permission given
here, feel free to contact us as
How to Contact Us

Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any addi-
tional information. You can access this page at:
/>To comment or ask technical questions about this book, send email to:

www.it-ebooks.info
Preface
|
xix
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our web site at:
/>Safari® Books Online
When you see a Safari® Books Online icon on the cover of your
favorite technology book, that means the book is available online
through the O’Reilly Network Safari Bookshelf.
Safari offers a solution that’s better than e-books. It’s a virtual library that lets you
easily search thousands of top tech books, cut and paste code samples, download
chapters, and find quick answers when you need the most accurate, current informa-
tion. Try it for free at .
Acknowledgments
The development of Programming Visual Basic 2008 has been a labor of love for me,
and I am blessed to have had so many others go through the labor with me. Joan
Murray from Addison-Wesley was my editor on the first edition of the book. John
Osborn at O’Reilly Media took up the task of guiding the second edition. I have been

fortunate to have worked with John on three different book projects, and their suc-
cess was possible thanks to his gallant efforts.
Several other authors and programmers took time out of their day jobs to review
each chapter of the book and point out its deficiencies, which were numerous before
their arrival. I especially wish to thank Glenn Berry, Alex Bierhaus, Harry Chen, Ken
Getz, Lowell Mauer, and Dan Sullivan for their superb comments. When it came
time to focus on Visual Basic’s 2008 release, I also received fantastic input from
Chris Williams, Daniel Seara, Ron Petrusha, and Sander Gerz.
Many thanks to Joe Binder, Jay Roxe, Prasadi de Silva, and Eric Knox, all members
of the Visual Basic team at Microsoft. Each of them fielded a relentless onslaught of
questions about esoteric Visual Basic and .NET features, and provided answers filled
with knowledge, patience, and grace.
My agent, Claudette Moore, always deserves her own paragraph in any computer
book I write. In fact, she would be a great subject for one of those literary-agent-
focused biographies that the public is always clamoring for. Not only does she do a
great job at all of the normal agenty things, but she also shares personally in the joys
and sorrows of the authors under her charge. Thank you for another fun year in
books.
www.it-ebooks.info
xx
|
Preface
To Maki, my wife, and to Spencer, my son, I give a special wave of thanks. If you’ve
ever spent time with authors, you know how cranky they can get. But Maki and
Spencer combat crankiness with care and love, and it works. The words thank you
seem so inadequate when I owe both of them so much. Thanks be to God because
He provided such a tremendous family to me.
www.it-ebooks.info
1
Chapter 1

CHAPTER 1
Introducing .NET1
Welcome to .NET! I might as well have said, “Welcome to the universe,” because
like the universe, .NET is huge. And it’s complex. And it’s filled with black holes and
other things that don’t always make sense. Yet it (.NET, not the universe) turns out
to be a fantastic system in which to develop software applications.
The .NET Framework was not developed in a vacuum (unlike the universe);
Microsoft designed it and its related development languages—especially C# and
Visual Basic—to address various issues that plagued Windows software developers
and users. To fully understand why .NET was necessary, we need to take a short trip
down computer memory lane.
Before .NET
Practical, general-purpose computers have been around since the mid-20th century.
However, they were inaccessible to most people because (a) they cost millions of dol-
lars; (b) they consumed gobs of electricity; (c) maintenance and programming could
be done only by highly trained specialists; and (d) they tended to clash with the liv-
ing room furniture.
Fast-forward about 30 years. IBM comes out with the “personal” computer. These
“desktop” computers represented a great advance in technology, but only a minority
of people ever used them. They continued to be expensive (thousands of dollars),
and maintenance and programming still required significant investments in training.
IBM PCs also looked hideous around the living room furniture.
Then came the Apple Macintosh. With its sleek design and its user-friendly function-
ality, it introduced the joy of computing to the masses. And while programming it
was not always straightforward, it did give nice results. It’s no wonder that Microsoft
decided to copy—oops, I mean improve upon—its functionality.
www.it-ebooks.info
2
|
Chapter 1: Introducing .NET

Microsoft Windows 1.0 brought a greater level of usability to the IBM/Intel comput-
ing platform. But it wasn’t a free ride for programmers. MS-DOS development was
hard enough without the addition of the “message pumps” and the hundreds of
Application Programming Interface (API) calls needed by Windows programs. Visual
Basic 1.0, introduced in 1991, greatly simplified the development process, but with
the advent of 32-bit systems, ActiveX and COM components, and the Web, even VB
programmers soon felt overwhelmed.
Throughout the 1990s, the situation only seemed to worsen. Microsoft saw increased
competition in the form of the Java™ language and the Linux operating system.
Hackers were exploiting buffer overruns and other security issues present in the
Windows platform. Users experienced myriad computer problems stemming from
conflicting standards, competing data integration technologies, registry bloat, and
“DLL hell.” In frustration, an Excel user’s group set fire to the entire Microsoft cam-
pus in Redmond.
Well, it didn’t get that bad. But Microsoft did see that it needed to address the over-
all software development and usability issues on its beloved Windows platform. Its
solution came in the form of the .NET Framework.
Back to Introducing .NET
When Microsoft announced its plans for .NET, it surprised many developers, espe-
cially Visual Basic developers, who saw it as a giant step backward for “Rapid Appli-
cation Development.” But the release of the .NET Framework version 1.0 in 2002
did bring many needed benefits:
.NET introduced a unified programming environment
All .NET-enabled languages compile to “Microsoft Intermediate Language”
before being assembled into platform-specific machine code. Visual Basic, C#,
and other .NET languages are wrappers around this common .NET “language.”
Since all .NET-enabled compilers speak the same underlying language, they no
longer suffer from the many data and language conflicts inherent in other cross-
language component-based systems such as COM. The .NET version of Visual
Studio also unified the standard user interface that lets programmers craft source

code.
.NET committed developers to object-oriented technologies
Not only does .NET fully embrace the object-oriented programming paradigm,
but everything in .NET is contained in an object: all data values, all source code
blocks, and the plumbing for all user-initiated events. Everything appears in the
context of an object.
www.it-ebooks.info
The .NET Object
|
3
.NET simplified Windows programming
Programming in Visual Basic before .NET was easy enough, until it came time to
interact with one of the API libraries, something that happened a lot in profes-
sional programming. With .NET, most of the regularly used APIs are replaced
with a hierarchy of objects providing access to many commonly needed Win-
dows features. Since the hierarchy is extensible, other vendors can add new func-
tionality without disrupting the existing framework.
.NET enhanced security
Users and administrators can now establish security rules for different .NET fea-
tures, to limit malicious programs from doing their damage. .NET’s “managed”
environment also resolves buffer overrun issues and memory leaks through fea-
tures such as strong data typing and garbage collection.
.NET enhanced developer productivity through standards
The .NET Framework is built upon and uses many new and existing standards,
such as XML and SOAP. This enhances data interchange not only on the Win-
dows platform, but also in interactions with other platforms and systems.
.NET enhanced web-based development
Until .NET, a lot of web-based development was done using scripting languages.
.NET brings the power of compiled, desktop development to the Internet.
.NET simplified the deployment of applications

If .NET is installed on a system, releasing a program can be as simple as copying
its EXE file to the target system (although an install program is much more user-
friendly). Features such as side-by-side deployment, ClickOnce deployment, and
an end to file version conflicts and “DLL hell” (the presence of multiple versions
of the same DLL on a system, or the inability to remove a version of a DLL)
make desktop and web-based deployments a snap.
If you didn’t understand some of the terms used in this section, that’s all right. You
will encounter them again, with explanations, in later chapters.
The .NET Object
To fully understand software development in .NET, you must understand what an
object is. (If you are familiar with object-oriented programming—OOP—you can
probably skip down to the next section, although you will miss some really great
content.) While some of this section’s information will also appear in Chapter 8, it is
so important to the discussion of .NET that a portion appears here as well.
www.it-ebooks.info

×