The .NET Framework has two components:

□ Common Language Runtime

□ .NET Framework class library

The Common Language Runtime (CLR) is the agent that manages your .NET applications at execution time. It provides core services such as memory, thread, and resource management. Applications that run on top of the CLR are known as managed code; all others are known as unmanaged code.

The .NET Framework class library is a comprehensive set of reusable classes that provides all the functionalities your application needs. This library enables you to develop applications ranging from desktop Windows applications to ASP.NET web applications, and Windows Mobile applications that run on Pocket PCs.

Common Language Runtime

The Common Language Runtime (CLR) is the virtual machine in the .NET Framework. It sits on top of the Windows operating system (Windows XP, Windows Vista, Windows Server 2008, and so on). A .NET application is compiled into a bytecode format known as MSIL (Microsoft Intermediate Language). During execution, the CLR JIT ( just-in-time) compiles the bytecode into the processor's native code and executes the application. Alternatively, MSIL code can be precompiled into native code so that JIT compiling is no longer needed; that speeds up the execution time of your application.

The CLR also provides the following services:

□ Memory management/garbage collection

□ Thread management

□ Exception handling

□ Security

.NET developers write applications using a .NET language such as C#, VB.NET, or C++. The MSIL bytecode allows .NET applications to be portable (at least theoretically) to other platforms because the application is compiled to native code only during runtime.

At the time of writing, Microsoft's implementation of the .NET Framework runs only on Windows operating systems. However, there is an open-source implementation of the .NET Framework, called 'Mono,' that runs on Mac and Linux.

Figure 1-1 shows the relationships between the CLR, unmanaged and managed code.

Figure 1-1

.NET Framework Class Library

The .NET Framework class library contains classes that allow you to develop the following types of applications:

□ Console applications

□ Windows applications

□ Windows services 

□ ASP.NET Web applications

□ Web Services

□ Windows Communication Foundation (WCF) applications

□ Windows Presentation Foundation (WPF) applications

□ Windows Workflow Foundation (WF) applications

The library's classes are organized using a hierarchy of namespaces. For example, all the classes for performing I/O operations are located in the System.IO namespace, and classes that manipulate regular expressions are located in the System.Text.RegularExpressions namespace.

The .NET Framework class library is divided into two parts:

□ Framework Class Library (FCL)

□ Base Class Library (BCL)

The BCL is a subset of the entire class library and contains the set of classes that provide core functionalities for your applications. Some of the classes in the BCL are contained in the mscorlib.dll, System.dll, and System.core.dll assemblies. The BCL is available to all the languages using the .NET Framework. It encapsulates all the common functions such as file handling, database access, graphics manipulation, and XML document manipulation.

The FCL is the entire class library and it provides the classes for you to develop all the different types of applications listed previously.

Figure 1-2 shows the key components that make up the .NET Framework.

Figure 1-2 

Assemblies and the Microsoft Intermediate Language (MSIL)

In .NET, an application compiled into MSIL bytecode is stored in an assembly. The assembly is contained in one or more PE (portable executable) files and may end with an EXE or DLL extension.

Some of the information contained in an assembly includes:

□ Manifest — Information about the assembly, such as identification, name, version, and so on.

□ Versioning — The version number of an assembly.

□ Metadata — Information that describes the types and methods of the assembly.

Assemblies are discussed in more detail in Chapter 15.

To get a better idea of a MSIL file and its content, take a look at the following example, which has two console applications — one written in C# and the other written in VB.NET.

The following C# code displays the 'Hello, World' string in the console window:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace HelloWorldCS {

 class Program {

  static void Main(string[] args) {

   Console.WriteLine('Hello, World!');

   Console.ReadLine();

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату