Tài liệu Applied Microsoft .NET Framework Programming - Pdf 90

Applied Microsoft .NET Framework Programming
Table of Contents
Applied Microsoft .NET Framework Programming.........................................................................1
Introduction........................................................................................................................................4
What Makes Up the Microsoft .NET Initiative..........................................................................7
An Underlying Operating System: Windows......................................................................7
Helpful Products: The .NET Enterprise Servers.................................................................7
Microsoft XML Web Services: .NET My Services..............................................................8
The Development Platform: The .NET Framework............................................................8
The Development Environment: Visual Studio .NET.......................................................11
Goal of This Book..................................................................................................................12
System Requirements............................................................................................................13
This Book Has No Mistakes...................................................................................................13
Support..................................................................................................................................13
Part I: Basics of the Microsoft .NET Framework...........................................................................15
Chapter List............................................................................................................................15
Chapter 1: The Architecture of the .NET Framework Development Platform............................16
Compiling Source Code into Managed Modules....................................................................16
Combining Managed Modules into Assemblies.....................................................................18
Loading the Common Language Runtime.............................................................................19
Executing Your Assembly’s Code..........................................................................................22
IL and Verification............................................................................................................27
The .NET Framework Class Library.......................................................................................29
The Common Type System...................................................................................................31
The Common Language Specification...................................................................................33
Interoperability with Unmanaged Code..................................................................................37
Chapter 2: Building, Packaging, Deploying, and Administering Applications and Types.......40
Overview................................................................................................................................40
.NET Framework Deployment Goals.....................................................................................40
Building Types into a Module.................................................................................................41
Combining Modules to Form an Assembly............................................................................47

Casting Between Types.......................................................................................................101
Casting with the C# is and as Operators........................................................................103
Namespaces and Assemblies..............................................................................................105
Chapter 5: Primitive, Reference, and Value Types.....................................................................109
Programming Language Primitive Types.............................................................................109
Checked and Unchecked Primitive Type Operations.....................................................112
Reference Types and Values Types....................................................................................114
Boxing and Unboxing Value Types......................................................................................118
Chapter 6: Common Object Operations......................................................................................128
Object Equality and Identity.................................................................................................128
Implementing Equals for a Reference Type Whose Base Classes Don’t Override
Object’s Equals.......................................................................................................129
Implementing Equals for a Reference Type When One or More of Its Base Classes
Overrides Object’s Equals.......................................................................................130
Implementing Equals for a Value Type..........................................................................131
Summary of Implementing Equals and the ==/!= Operators..........................................133
Identity...........................................................................................................................134
Object Hash Codes..............................................................................................................134
Object Cloning.....................................................................................................................136
Part III: Designing Types...............................................................................................................139
Chapter List..........................................................................................................................139
Chapter 7: Type Members and Their Accessibility.....................................................................140
Type Members.....................................................................................................................140
Accessibility Modifiers and Predefined Attributes................................................................142
Type Predefined Attributes.............................................................................................144
Field Predefined Attributes.............................................................................................144
Method Predefined Attributes.........................................................................................145
Chapter 8: Constants and Fields..................................................................................................147
Constants.............................................................................................................................147
Fields...................................................................................................................................148

String Interning...............................................................................................................210
String Pooling.................................................................................................................213
Examining a String’s Characters....................................................................................213
Other String Operations.................................................................................................216
Dynamically Constructing a String Efficiently.......................................................................217
Constructing a StringBuilder Object...............................................................................217
StringBuilder’s Members................................................................................................218
Obtaining a String Representation for an Object.................................................................220
Specific Formats and Cultures.......................................................................................221
Formatting Multiple Objects into a Single String............................................................224
Providing Your Own Custom Formatter.........................................................................226
Parsing a String to Obtain an Object...................................................................................228
Encodings: Converting Between Characters and Bytes......................................................232
Encoding/Decoding Streams of Characters and Bytes..................................................238
Base−64 String Encoding and Decoding.......................................................................239
iii
Table of Contents
Chapter 13: Enumerated Types and Bit Flags............................................................................240
Enumerated Types...............................................................................................................240
Bit Flags...............................................................................................................................244
Chapter 14: Arrays.........................................................................................................................247
Overview..............................................................................................................................247
All Arrays Are Implicitly Derived from System.Array............................................................249
Casting Arrays.....................................................................................................................251
Passing and Returning Arrays.............................................................................................252
Creating Arrays That Have a Nonzero Lower Bound...........................................................253
Fast Array Access................................................................................................................254
Redimensioning an Array.....................................................................................................257
Chapter 15: Interfaces...................................................................................................................259
Interfaces and Inheritance...................................................................................................259

The finally Block.............................................................................................................312
iv
Table of Contents
Chapter 18: Exceptions
What Exactly Is an Exception?............................................................................................312
The System.Exception Class...............................................................................................316
FCL−Defined Exception Classes.........................................................................................317
Defining Your Own Exception Class....................................................................................319
How to Use Exceptions Properly.........................................................................................322
You Can’t Have Too Many finally Blocks.......................................................................323
Don’t Catch Everything..................................................................................................324
Gracefully Recovering from an Exception......................................................................325
Backing Out of a Partially Completed Operation When an Unrecoverable Exception
Occurs.....................................................................................................................326
Hiding an Implementation Detail....................................................................................327
What’s Wrong with the FCL.................................................................................................329
Performance Considerations...............................................................................................330
Catch Filters.........................................................................................................................333
Unhandled Exceptions.........................................................................................................335
Controlling What the CLR Does When an Unhandled Exception Occurs......................339
Unhandled Exceptions and Windows Forms.................................................................340
Unhandled Exceptions and ASP.NET Web Forms........................................................342
Unhandled Exceptions and ASP.NET XML Web Services............................................342
Exception Stack Traces.......................................................................................................342
Remoting Stack Traces..................................................................................................344
Debugging Exceptions.........................................................................................................345
Telling Visual Studio What Kind of Code to Debug........................................................349
Chapter 19: Automatic Memory Management (Garbage Collection)........................................351
Understanding the Basics of Working in a Garbage−Collected Platform.............................351
The Garbage Collection Algorithm.......................................................................................354

Reflecting Over an Assembly’s Types.................................................................................401
Reflecting Over an AppDomain’s Assemblies.....................................................................403
Reflecting Over a Type’s Members: Binding........................................................................404
Explicitly Loading Assemblies..............................................................................................405
Loading Assemblies as “Data Files”...............................................................................407
Building a Hierarchy of Exception−Derived Types.........................................................408
Explicitly Unloading Assemblies: Unloading an AppDomain...............................................410
Obtaining a Reference to a System.Type Object.................................................................412
Reflecting Over a Type’s Members......................................................................................415
Creating an Instance of a Type......................................................................................417
Calling a Type’s Method.................................................................................................418
Bind Once, Invoke Multiple Times..................................................................................422
Reflecting Over a Type’s Interfaces.....................................................................................426
Reflection Performance.......................................................................................................428
List of Figures................................................................................................................................429
List of Tables..................................................................................................................................432
vi
Applied Microsoft .NET Framework Programming
Jeffrey Richter
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052−6399
Copyright © 2002 by Jeffrey Richter
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 Cataloging−in−Publication Data
Richter, Jeffrey.
Applied Microsoft .NET Framework Programming / Jeffrey Richter.

Your smile brightens my every day.
Your zest makes my heart sing.
I love you.
Jeffrey Richter
Jeffrey Richter is a co−founder of Wintellect ( a training, design, and
debugging company dedicated to helping companies produce better software faster. Jeff has written
many books, including Programming Applications for Microsoft Windows (Microsoft Press, 1999)
and Programming Server−Side Applications for Microsoft Windows 2000 (Microsoft Press, 2000).
Jeff is also a contributing editor for MSDN Magazine, where he has written several feature articles
and is the .NET columnist. Jeff also speaks at various trade conferences worldwide, including
VSLive!, WinSummit, and Microsoft’s TechEd and PDC.
Jeff has consulted for many companies, including AT&T, DreamWorks, General Electric,
Hewlett−Packard, IBM, and Intel. Jeff’s code has shipped in many Microsoft products, among them
Visual Studio, Microsoft Golf, Windows Sound System, and various versions of Windows, from
Windows 95 to Windows XP and the Windows .NET Server Family. Since October 1999, Jeff has
consulted with the .NET Framework team and has used the .NET Framework to produce the XML
Web service front end to Microsoft’s very popular TerraServer Web property
( />On the personal front, Jeff holds both airplane and helicopter pilot licenses, though he never gets to
fly as often as he’d like. He is also a member of the International Brotherhood of Magicians and
enjoys showing friends slight−of−hand card tricks from time to time. Jeff’s other hobbies include
music, drumming, and model railroading. He also enjoys traveling and the theater. He lives near
Bellevue, Washington, with his wife, Kristin, and their cat, Max. He doesn’t have any children yet,
but he has the feeling that kids may be a part of his life soon.
Acknowledgments
I couldn’t have written this book without the help and technical assistance of many people. In
particular, I’d like to thank the following people:
Members of the Microsoft Press editorial team: Sally Stickney, project editor and
manuscript editor; Devon Musgrave, manuscript editor; Jim Fuchs, technical editing
consultant; Carl Diltz and Katherine Erickson, compositors; Joel Panchot, artist; and Holly M.
Viola, copy editor.


3
Introduction
Over the years, our computing lifestyles have changed. Today, everyone sees the value of the
Internet, and our computing lifestyle is becoming more and more dependent on Web−based
services. Personally, I love to shop, get traffic conditions, compare products, buy tickets, and read
product reviews all via the Internet.
However, I’m finding that there are still many things I’d like to do using the Internet that aren’t
possible today. For example, I’d like to find restaurants in my area that serve a particular cuisine.
Furthermore, I’d like to be able to ask if the restaurant has any seating for, say, 7:00 p.m. that night.
Or if I had my own business, I might like to know which vendor has a particular item in stock. If
multiple vendors can supply me with the item, I’d like to be able to find out which vendor offers the
least expensive price for the item or maybe which vendor can deliver the item to me the fastest.
Services like these don’t exist today for two main reasons. The first reason is that no standards are
in place for integrating all this information. After all, vendors today each have their own way of
describing what they sell. The emerging standard for describing all types of information is Extensible
Markup Language (XML). The second reason these services don’t exist today is the complexity of
developing the code necessary to integrate such services.
Microsoft has a vision in which selling services is the way of the future—that is, companies will offer
services and interested users can consume these services. Many services will be free; others will
be available through a subscription plan, and still others will be charged per use. You can think of
these services as the execution of some business logic. Here are some examples of services:
Validating a credit card purchase•
Getting directions from point A to point B•
Viewing a restaurant’s menu•
Booking a flight on an airline, a hotel room, or a rental car•
Updating photos in an online photo album•
Merging your calendar and your children’s calendars to plan a family vacation•
Paying a bill from a checking account•
Tracking a package being shipped to you•

The following figure shows a bunch of XML Web services all communicating with one another using
SOAP with its XML payload. The figure also shows clients running applications that can talk to Web
services and even other clients via SOAP (XML). In addition, the figure shows a client getting its
results via HTML from a Web server. Here the user probably filled out a Web form, which was sent
back to the Web server. The Web server processed the user’s request (which involved
communicating with some Web services), and the results are ultimately sent back to the user via a
standard HTML page.
5
In addition, the computers providing the services must be running an operating system that is
listening for these SOAP requests. Microsoft hopes that this operating system will be Windows, but
Windows isn’t a requirement. Any operating system that can listen on a TCP/IP socket port and
read/write bytes to the port is good enough. In the not too distant future, mobile phones, pagers,
automobiles, microwave ovens, refrigerators, watches, stereo equipment, game consoles, and all
kinds of other devices will also be able to participate in this new world.
On the client or application side, an operating system must be running that can read/write to a
socket port to issue service requests. The client’s computer must also be capable of supporting
whatever features the user’s application desires. If the user’s application wants to create a window
or a menu, the operating system must provide this functionality or the application developer must
implement it manually. Of course, Microsoft hopes that people will write applications that take
advantage of the rich feature set in Windows, but again, Windows is a recommendation, not a
necessity.
What I’m trying to say is that this new world will happen whether Microsoft is a part of it or not.
Microsoft’s .NET initiative is all about making it really easy for developers to create and access
these services.
Today, we could all go write our own operating system and create our own custom Web servers to
listen and manually process SOAP requests if we wanted to, but it’s really hard and would take a
long time. Microsoft has taken on all this hard work for us, and we can just leverage Microsoft’s
efforts to greatly simplify our own development efforts. Now we, as application developers, can
concentrate and focus on our business logic and services, leaving all the communication protocols
and plumbing to Microsoft (who has a lot of developers that just love to do this nitty−gritty stuff).

In addition, Windows XP and the Windows .NET Server Family products have some built−in support
for loading and executing applications implementing the .NET Framework. Finally, Windows XP and
the Windows .NET Server Family operating systems have a new, extensible instant messaging
notification application. This application allows third−party vendors (such as Expedia, the United
States Postal Service, and many others) to communicate with users seamlessly. For example,
users can receive automatic notifications when their flights are delayed (from Expedia) and when a
package is ready to be delivered (from the U.S. Postal Service).
I don’t know about you, but I’ve been hoping for services like these for years—I can’t wait!
Helpful Products: The .NET Enterprise Servers
As part of the .NET initiative, Microsoft is providing several products that companies can choose to
use if their business logic (services) find them useful. Here are some of Microsoft’s enterprise server
products:
Microsoft Application Center 2000•
7
Microsoft BizTalk Server 2000•
Microsoft Commerce Server 2000•
Microsoft Exchange 2000•
Microsoft Host Integration Server 2000•
Microsoft Internet Security and Acceleration (ISA) Server 2000•
Microsoft Mobile Information Server 2002•
Microsoft SQL Server 2000•
It’s likely that each of these products will eventually have a “.NET” added to its name for marketing
purposes. But I’m also sure that over time, these products will integrate more .NET features into
them as Microsoft continues the initiative.
Microsoft XML Web Services: .NET My Services
Certainly, Microsoft wants to do more than just provide the underlying technologies that allow others
to play in this new world. Microsoft wants to play too. So, Microsoft will be building its own set of
XML Web services: some will be free, and others will require some usage fee. Microsoft initially
plans to offer the following .NET My Services:
.NET Alerts•

applications and Web services, the .NET Framework is capable of a lot more. All in all,
the .NET Framework development platform allows developers to build the following
kinds of applications: XML Web services, Web Forms, Win32 GUI applications, Win32
CUI (console UI) applications, services (controlled by the Service Control Manager),
utilities, and stand−alone components. The material presented in this book is applicable
to any and all of these application types.
The .NET Framework consists of two parts: the common language runtime (CLR) and the
Framework Class Library (FCL). The .NET Framework is the part of the initiative that makes
developing services and applications really easy. And, most important, this is what this book is all
about: developing applications and XML Web services for the .NET Framework.
Initially, Microsoft will make the CLR and FCL available in the various versions of Windows,
including Windows 98, Windows 98 Second Edition, and Windows Me as well as Windows NT 4,
Windows 2000, and both 32−bit and 64−bit versions of Windows XP and the Windows .NET Server
Family. A “lite” version of the .NET Framework, called the.NET Compact Framework, is also
available for PDAs (such as Windows CE and Palm) and appliances (small devices). On December
13, 2001, the European Computer Manufacturers Association (ECMA) accepted the C#
programming language, portions of the CLR, and portions of the FCL as standards. It won’t be long
before ECMA−compliant versions of these technologies appear on a wide variety of operating
systems and CPUs.
NoteWindows XP (both Home Edition and Professional) doesn’t ship with the .NET Framework “in
the box.” However, the Windows .NET Server Family (Windows .NET Web Server, Windows
.NET Standard Server, Windows .NET Enterprise Server, and Windows .NET Datacenter
Server) will include the .NET Framework. In fact, this is how the Windows .NET Server Family
got its name. The next version of Windows (code−named “Longhorn”) will include the .NET
Framework in all editions. For now, you’ll have to redistribute the .NET Framework with your
application, and your setup program will have to install it. Microsoft does make a .NET
Framework redistribution file that you’re allowed to freely distribute with your
application: />Almost all programmers are familiar with runtimes and class libraries. I’m sure many of you have at
least dabbled with the C−runtime library, the standard template library (STL), the Microsoft
Foundation Class library (MFC), the Active Template Library (ATL), the Visual Basic runtime library,

always run. This slams shut the gates of “DLL hell.”

Simplified deployment Today, Windows applications are incredibly difficult to set up and
deploy. Several files, registry settings, and shortcuts usually need to be created. In addition,
completely uninstalling an application is nearly impossible. With Windows 2000, Microsoft
introduced a new installation engine that helps with all these issues, but it’s still possible that
a company authoring a Microsoft installer package might fail to do everything correctly. The
.NET Framework seeks to banish these issues into history. The .NET Framework
components (known simply as types) are not referenced by the registry. In fact, installing
most .NET Framework applications requires no more than copying the files to a directory
and adding a shortcut to the Start menu, desktop, or Quick Launch bar. Uninstalling the
application is as simple as deleting the files.

Wide platform reach When compiling source code for the .NET Framework, the compilers
produce common intermediate language (CIL) instead of the more traditional CPU
instructions. At run time, the CLR translates the CIL into native CPU instructions. Because
the translation to native CPU instructions is done at run time, the translation is done for the
host CPU. This means that you can deploy your .NET Framework application on any
machine that has an ECMA−compliant version of the CLR and FCL running on it. These
machines can be x86, IA64, Alpha, PowerPC, and so on. Users will immediately appreciate
the value of this broad execution if they ever change their computing hardware or operating
system.

Programming language integration COM allows different programming languages to
interoperate with one another. The .NET Framework allows languages to be integrated with
one another so that you can use types of another language as if they are your own. For
example, the CLR makes it possible to create a class in C++ that derives from a class
implemented in Visual Basic. The CLR allows this because it defines and provides a
Common Type System (CTS) that all programming languages that target the CLR must use.
The Common Language Specification (CLS) describes what compiler implementers must do

classic system attacks (for example, exploiting buffer overruns).

Rich debugging support Because the CLR is used for many programming languages, it is
now much easier to implement portions of your application using the language best suited to
a particular task. The CLR fully supports debugging applications that cross language
boundaries.

Consistent method failure paradigm One of the most aggravating aspects of Windows
programming is the inconsistent style that functions use to report failures. Some functions
return Win32 status codes, some functions return HRESULTs, and some functions throw
exceptions. In the CLR, all failures are reported via exceptions—period. Exceptions allow the
developer to isolate the failure recovery code from the code required to get the work done.
This separation greatly simplifies writing, reading, and maintaining code. In addition,
exceptions work across module and programming language boundaries. And, unlike status
codes and HRESULTs, exceptions can’t be ignored. The CLR also provides built−in
stack−walking facilities, making it much easier to locate any bugs and failures.

Security Traditional operating system security provides isolation and access control based
on user accounts. This model has proven useful, but at its core assumes that all code is
equally trustworthy. This assumption was justified when all code was installed from physical
media (for example, CD−ROM) or trusted corporate servers. But with the increasing reliance
on mobile code such as Web scripts, applications downloaded over the Internet, and e−mail
attachments, we need ways to control the behavior of applications in a more code−centric
manner. Code access security provides a means to do this.

Interoperability Microsoft realizes that developers already have an enormous amount of
existing code and components. Rewriting all this code to take full advantage of the .NET
Framework platform would be a huge undertaking and would prevent the speedy adoption of
this platform. So the .NET Framework fully supports the ability for the developer to access
their existing COM components as well as call Win32 functions in existing DLLs.

the core types that every developer needs to be aware of. And while this book isn’t specifically
about Windows Forms, XML Web services, Web Forms, and so on, the technologies presented in
the book are applicable to all these application types.
With this book, I’m not attempting to teach you any particular programming language. I’m assuming
that you’re familiar with a programming language such as C++, C#, Visual Basic, or Java. I also
assume that you’re familiar with object−oriented programming concepts such as data abstraction,
inheritance, and polymorphism. A good understanding of these concepts is critical because all .NET
Framework features are offered via an object−oriented paradigm. If you’re not familiar with these
concepts, I strongly suggest you first find a book that teaches these concepts.
Although I don’t intend to teach basic programming, I will spend time on various programming topics
that are specific to the .NET Framework. All .NET Framework developers must be aware of these
topics, which I explain and use throughout this book.
Finally, because this is a book about the .NET Framework’s common language runtime, it’s not
about programming in any one specific programming language. However, I provide lots of code
examples in the book to show how things really work. To remain programming language agnostic,
the best language for me to use for these examples would be IL (intermediate language) assembly
language. IL is the only programming language that the CLR understands. All language compilers
compile source code to IL, which is later processed by the CLR. Using IL, you can access every
feature offered by the CLR.
However, using IL assembly language is a pretty low−level way to write programs and isn’t an ideal
way to demonstrate programming concepts. So I decided to use C# as my programming language
of choice throughout this entire book. I chose C# because it is the language Microsoft designed
specifically for developing code for the .NET Framework. If you’ve decided not to use C# for your
programming projects, that’s OK—I’ll just assume that you can read C# even if you’re not
12
programming in it.
System Requirements
The .NET Framework will install on Windows 98, Windows 98 Second Edition, Windows Me,
Windows NT 4 (all editions), Windows 2000 (all editions), Windows XP (all editions), and the
Windows .NET Server Family servers. You can download it from


14
Part I: Basics of the Microsoft .NET Framework
Chapter List
Chapter 1: The Architecture of the .NET framework Development Platform
Chapter 2: Building, Packaging, Deploying, and Administering Applications and Types
Chapter 3: Shared Assemblies
15
Chapter 1: The Architecture of the .NET Framework
Development Platform
The Microsoft .NET Framework introduces many new concepts, technologies, and terms. My goal in
this chapter is to give you an overview of how the .NET Framework is architected, introduce you to
some of the new technologies the framework includes, and define many of the terms you’ll be
seeing when you start using it. I’ll also take you through the process of building your source code
into an application or a set of redistributable components (types) and then explain how these
components execute.
Compiling Source Code into Managed Modules
OK, so you’ve decided to use the .NET Framework as your development platform. Great! Your first
step is to determine what type of application or component you intend to build. Let’s just assume
that you’ve completed this minor detail, everything is designed, the specifications are written, and
you’re ready to start development.
Now you must decide what programming language to use. This task is usually difficult because
different languages offer different capabilities. For example, in unmanaged C/C++, you have pretty
low−level control of the system. You can manage memory exactly the way you want to, create
threads easily if you need to, and so on. Visual Basic 6, on the other hand, allows you to build UI
applications very rapidly and makes it easy for you to control COM objects and databases.
The common language runtime (CLR) is just what its name says it is: a runtime that is usable by
different and varied programming languages. The features of the CLR are available to any and all
programming languages that target it—period. If the runtime uses exceptions to report errors, then
all languages get errors reported via exceptions. If the runtime allows you to create a thread, then

Object File Format (COFF) header. This header indicates the type of file:
GUI, CUI, or DLL, and it also has a timestamp indicating when the file was
built. For modules that contain only IL code, the bulk of the information in
the PE header is ignored. For modules that contain native CPU code, this
header contains information about the native CPU code.
CLR header Contains the information (interpreted by the CLR and utilities) that makes
this a managed module. The header includes the version of the CLR
required, some flags, the MethodDef metadata token of the managed
module’s entry point method (Main method), and the location/size of the
module’s metadata, resources, strong name, some flags, and other less
interesting stuff.
Metadata Every managed module contains metadata tables. There are two main
types of tables: tables that describe the types and members defined in your
source code and tables that describe the types and members referenced
by your source code.
Intermediate language
(IL) code
Code that the compiler produced as it compiled the source code. The CLR
later compiles the IL into native CPU instructions.
Most compilers of the past produced code targeted to a specific CPU architecture, such as x86,
IA64, Alpha, or PowerPC. All CLR−compliant compilers produce IL code instead. (I’ll go into more
detail about IL code later in this chapter.) IL code is sometimes referred to as managed code
because the CLR manages its lifetime and execution.
In addition to emitting IL, every compiler targeting the CLR is required to emit full metadata into
every managed module. In brief, metadata is simply a set of data tables that describe what is
defined in the module, such as types and their members. In addition, metadata also has tables
17
indicating what the managed module references, such as imported types and their members.
Metadata is a superset of older technologies such as type libraries and interface definition language
(IDL) files. The important thing to note is that CLR metadata is far more complete. And, unlike type

familiar with. These modules don’t require the CLR in order to execute. However, by specifying a
new command−line switch, the C++ compiler can produce managed modules that do require the
CLR to execute. Of all the Microsoft compilers mentioned, C++ is unique in that it is the only
language that allows the developer to write both managed and unmanaged code and have it
emitted into a single module. This can be a great feature because it allows developers to write the
bulk of their application in managed code (for type safety and component interoperability) but
continue to access their existing unmanaged C++ code.
Combining Managed Modules into Assemblies
The CLR doesn’t actually work with modules; it works with assemblies. An assembly is an abstract
concept that can be difficult to grasp initially. First, an assembly is a logical grouping of one or more
managed modules or resource files. Second, an assembly is the smallest unit of reuse, security,
and versioning. Depending on the choices you make with your compilers or tools, you can produce
a single−file or a multifile assembly.
In Chapter 2, I’ll go over assemblies in great detail, so I don’t want to spend a lot of time on them
here. All I want to do now is make you aware that there is this extra conceptual notion that offers a
18


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status