Home > Articles > Programming > Windows Programming

This chapter is from the book

Introduction to Microsoft .NET Framework

Microsoft .NET Framework is a new programming model that simplifies application development for the highly distributed environment of the Internet. The major components of the .NET Framework are the CLR and the .NET Framework class library. Figure 1-2 shows the architecture of the Microsoft

Figure 1-2Figure 1-2 Microsoft.NET Framework.

Windows Forms are used in developing rich GUI desktop .NET applications. Web Forms are used to develop Web applications. With the introduction of Web Forms, the .NET Framework brings the ease of drag and drop designing into Web application development.

ADO.NET brings with it the concept of disconnected data access. This vastly improves the performance of ASP.NET applications. ADO.NET components have been logically grouped into data access and data manipulation components. The data access components first access the data. Then a connection with the data source is no longer required. Once data has been retrieved, the data manipulation components manipulate the data according to the business logic. The ADO.NET classes are found in the System.Data namespace. The concept of namespaces is covered in a later section in this chapter.

The CLR, CTS, and the CLS are explained in more detail in the next subsections.

Introduction to the CLR

The CLR is the execution environment provided by the Microsoft .NET Framework. It provides many services such as

  • Automatic garbage collection
  • Code access security
  • Simplified versioning
  • Simple and reliable deployment
  • Deep cross-language interoperability
  • Debugging across different languages
  • Performance
  • Scalability

Because the CLR manages the code execution, all the code that is targeted for the CLR is known as managed code. Managed code emits metadata along with the executable. This metadata is used to describe the types (classes) and members used in the code, along with all the external references used in executing the code. The CLR uses this metadata to load the classes during execution and resolve method invocations during runtime.

The CLR provides automatic garbage collection of the objects that have been loaded into memory. All objects that are created via the new operator are allocated memory on the heap. A program can allocate as many objects as are required by the program logic. However, when an object is no longer required, there must be some mechanism to free up the memory that was occupied by the object.

This is accomplished in the CLR via a program called garbage collector, which collects all objects in memory that have no references. This program runs as a low-priority thread in the background process and collects all unreferenced objects. Because memory management is automatic, the chances for memory leaks in the program are minimized. However, the time when garbage collector would actually release the objects from the memory is not known. This concept is known as nondeterministic garbage collection because it cannot be determined in advance when the objects would be released from memory.

If sufficient memory is not available for creating new objects, the CLR throws an exception that can be caught and gracefully handled by the application.

Code Access Security (CAS), as the name suggests, is used to control the access that the code has to system resources. The CLR has a runtime security system. Administrators can configure policy settings by specifying the resources that can be accessed by the code.

A call stack is created that represents the order in which the assemblies get called. The CLR's security system walks the stack to determine whether the code is authorized to access the system resources or perform certain operations. If any caller in the call stack does not have the requisite permission to access the specific system resources, a security exception is thrown by the CLR.

Simplified versioning is another feature provided in the .NET Framework. It supports versioning and also provides for side-by-side execution of different versions of the same component. The specific versions of the assembly and the dependent assemblies are stored in the assembly's manifest. The copies of the same assembly that differ only in version numbers are considered to be different assemblies by the CLR. Assemblies are explained in more detail in the later sections.

Simplified deployment is one of the features provided in the .NET Framework. The most important point to mention is that .NET components do not need to be registered in the Windows registry. All code generated in the .NET Framework is self-describing because assemblies contain the manifest and metadata information. This information contains all the data about the dependencies of the assembly and the specific versions of the components that these assemblies would use at execution time; therefore, multiple versions of the same components can coexist. The CLR enforces the versioning policy.

Cross-language interoperability is an important feature, and it was one of the design goals of the .NET Framework. This feature is possible because of the CTS and CLS. The CTS is explained in more detail in the next subsection.

Visual Studio .NET allows for debugging across an application consisting of different languages targeted for the CLR. In fact, the IDE also allows for debugging an application in which managed code interacts with unmanaged code.

CLR ensures that performance of the code execution is optimized. Compiled code is stored in cache. When the same code is called next time, this code is loaded into memory from cache. This advantage stands out more in the case of ASP.NET applications than for ASP applications. ASP code was interpreted every time an ASP page was requested. In ASP.NET, the code is compiled only once when the page is requested for the first time. This ensures that performance is optimized.

The .NET Framework also provides some classes for tracking the performance of the .NET applications. These classes are known as performance counters. The .NET Framework provides performance counters for getting information on exception handling, interoperation with unmanaged code, loading and unloading code into memory, locking and threading, memory, networking operations, and so on. These performance counters help to fine-tune the performance of the .NET applications.

Introduction to the CTS

The CTS defines how types are declared, used, and managed in the runtime environment. The CTS is the key element for the CLR's support of cross-language integration. The common type system is used to

  • Enable cross-language integration, type safety, and high-performance code execution.

  • Define rules that languages should follow. This helps to ensure that objects written in different languages can interact with each other.

The Microsoft .NET Framework supports two categories of types, reference and value. As the name suggests, reference types contain a reference to memory address of a value stored in memory. If any changes are made to the value using the reference address, the original value is changed in memory. Reference type variables are allocated in the heap memory.

Value types, on the other hand, contain the actual value. If the value of one variable (of value type) is assigned to another variable (of value type), the contents of the first variable are copied into the second variable. If any changes are made in the second variable, the contents of the first variable are not changed. Value type variables are allocated on the stack. Value types are stored more efficiently as primitive types. Value types are derived from the System.ValueType class. Because of this, the value type variables can have fields, properties, and events, just as reference type of variables.

Microsoft .NET has introduced a concept called boxing and unboxing. Boxing involves the process of converting a value type variable into a reference type variable. Boxing a variable of a value type allocates an object instance on the heap and copies the value of the value type variable into the heap. Unboxing is the explicit conversion from the object type to a value type. During unboxing an InvalidCastException might be thrown if the source argument is null or is a reference to an incompatible type.

A type definition includes the type name, visibility, base type, interfaces implemented by the new type, and members of the new type. A type needs to be identified by a name. It can have global access; that is, all other assemblies can access the type if the accessibility of the type is public. If the accessibility of the type is assembly, the type can be accessed only within the assembly in which the type is defined. A type can inherit from other types and extend the behavior of the base types. A type can inherit only from a single type. It can also implement any number of interfaces. In addition, attributes can be used with the types to provide more information about the types.

Value types are built-in data types provided by the programming languages supported in the Microsoft .NET Framework. Integer, Float, and Double are some examples of built-in data types and are value types. User-defined value types can be defined. Structure is a common example of a user-defined value type that is supported in Visual Basic .NET.

Some of the reference types found in the Microsoft .NET Framework are the classes, arrays, pointers, delegates, and so on.

Introduction to the CLS

The CLS rules define the basic language features required by many applications and promoting language interoperability. The CLS defines a subset of the CTS (explained in the previous section). All languages targeted for the Microsoft .NET Framework comply with the CLS. This ensures language interoperability between the various languages. The CLS also establishes requirements for CLS compliance; these help developers determine whether their managed code conforms to the CLS.

The CLS rules are normally used from the perspective of the high-level source code and tools, such as compilers, that are used in the process of generating assemblies in the Microsoft .NET Framework.

The CLS rules apply only to externally visible items. Within a single assembly there are no restrictions to the programming techniques that are used. Code can be marked as CLS compliant or otherwise with the help of custom attributes.

An assembly can contain many types. If an assembly is marked as CLS compliant with a custom attribute, all types within that assembly are automatically CLS compliant. However, one can also mark individual types with custom attributes to make them non-CLS compliant. Similarly, if a type is marked as CLS compliant, all the members of that type are automatically CLS compliant unless marked as non-CLS compliant with the help of attributes.

Most of the classes found in the .NET Framework class library are CLS compliant. Thus, these classes can be used from all languages that are targeted for the .NET Framework.

Understanding Compilation in .NET Framework

Compilation is a two-step process in the .NET Framework, as shown in Figure 1-3. In the first step, the language compiler generates Microsoft

Figure 1-3Figure 1-3 Compilation in Microsoft.NET.

In the second step of compilation, the just-in-time (JIT) compiler compiles MSIL into native code, which can be executed on specific hardware and operating systems. The JIT compiler is a part of the runtime execution environment.

In Microsoft .NET there are three types of JIT compilers:

  • Pre-JIT. Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

  • Econo-JIT. Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.

  • Normal-JIT. Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

The security policy settings are referred at the compilation stage. If the code is not type-safe, the JIT process is aborted and an exception is raised. This type safety is ensured during compilation using JIT.

Overall the role of a JIT compiler is to bring higher performance by placing the compiled code in cache so that when the next call is made to the same method or procedure, it gets executed at a faster speed.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020