.NET Framework Classes
Perhaps one of the biggest benefits of writing
managed code, at least from a developerβs point of view, is that
you get to use the .NET base class
library.
The .NET base classes are a massive collection of
managed code classes that allow you to do almost any of the tasks
that were previously available through the Windows API. These
classes follow the same object model IL uses, based on single
inheritance. This means that you can either instantiate objects of
whichever .NET base class is appropriate or you can derive your own
classes from them.
The great thing about the .NET base classes is that
they have been designed to be very intuitive and easy to use. For
example, to start a thread, you call the Start() method of the Thread class. To disable a TextBox, you set the Enabled property of a TextBox object to false.
This approach - while familiar to Visual Basic and Java developers,
whose respective libraries are just as easy to use - will be a
welcome relief to C++ developers, who for years have had to cope
with such API functions as GetDIBits(),
RegisterWndClassEx(), and IsEqualIID(), as well as a whole plethora of
functions that required Windows handles to be passed around.
On the other hand, C++ developers always had easy
access to the entire Windows API, whereas Visual Basic 6 and Java
developers were more restricted in terms of the basic operating
system functionality that they have access to from their respective
languages. What is new about the .NET base classes is that they
combine the ease of use that was typical of the Visual Basic and
Java libraries with the relatively comprehensive coverage of the
Windows API functions. Many features of Windows still are not
available through the base classes, and for those you will need to
call into the API functions, but in general, these are now confined
to the more exotic features. For everyday use, you will probably
find the base classes adequate. And if you do need to call into an
API function, .NET offers a so-called platform-invoke that ensures data types are
correctly converted, so the task is no harder than calling the
function directly from C++ code would have been - regardless of
whether you are coding in C#, C++, or Visual Basic 2009.
|
|
Tip |
WinCV, a Windows-based utility, can be used
to browse the classes, structs, interfaces, and enums in the base
class library. WinCV is discussed in Chapter 14, βVisual
Studio 2009.β
|
Although Chapter 3 is nominally dedicated
to the subject of base classes, in reality, once we have completed
our coverage of the syntax of the C# language, most of the rest of
this site shows you how to use various classes within the .NET base
class library for both .NET 2.0 and the new .NET Framework 3.0.
That is how comprehensive base classes are. As a rough guide, the
areas covered by the .NET 2.0 and 3.0 base classes include:
-
Core features provided by IL (including the
primitive data types in the CTS discussed in Chapter
3, βObjects and Typesβ)
-
Windows GUI support and controls (see
Chapter 28, βWindows Forms,β and 31,
βWindows Presentation Foundationβ)
-
Web Forms (ASP.NET, discussed in Chapters
32, βASP.NET Pagesβ and 33, βASP.NET
Developmentβ)
-
Data access (ADO.NET; see Chapters
25, βData Access with .NET,β 27,
β.NET Programming with SQL Server 2009,β and
26, βManipulating XMLβ)
-
Directory access (see Chapter
42, βDirectory Servicesβ)
-
File system and registry access (see Chapter
24, βManipulating Files and the Registryβ)
-
Networking and Web browsing (see Chapter
35, βAccessing the Internetβ)
-
.NET attributes and reflection (see Chapter
12, βReflectionβ)
-
Access to aspects of the Windows OS
(environment variables and so on; see Chapter 19, β.NET
Securityβ)
-
COM interoperability (see Chapters 38,
βEnterprise Servicesβ and 23,
βCOM Interoperabilityβ)
Incidentally, according to Microsoft sources,
a large proportion of the .NET base classes have actually been
written in C#!