Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

.

NET Framework
The .NET Framework is the heart of Microsoft .NET. The .NET Framework is a
software development platform of Microsoft .NET. Like any platform, it provides a runtime,
defines functionality in some libraries, and supports a set of programming languages. The .NET
Framework provides the necessary compile-time and run-time foundation to build and run
.NET-based applications.

The .NET Framework consists of:


• Common Language Runtime
• Class Libraries
• Support for Multiple Programming Language

The common language runtime (CLR) (also refer as runtime). The Common Language
Runtime is the core of Microsoft‟s .NET vision. This is said to be the execution engine
of .NET platform. The runtime (CLR) handles runtime services, including language integration,
security, and memory management. During development, the runtime (CLR) provides features
that are needed to simplify development.
Class libraries: Class libraries provide reusable code for most common tasks, including
data access, XML Web service development, and Web and Windows Forms. The CLR Software
Development Kit (SDK) provides the programming APIs in the form of a set of classes for
building .NET applications. Collectively, they are referred to the Base Class Library, or BCL.
Through the classes in the BCL, we can interact with the runtime, influencing the way
that the runtime‟s services are provided to us. In addition to giving us an “in” to the runtime, the
BCL classes provide a large number of useful utilities. These include things like a
new database access library (ADO.NET), ASP.NET, and an XML parser with support for the
latest XML specifications. In addition, developers can extend classes by creating their own
libraries of classes. All applications (Web, Windows, and XML Web services) access the same
.NET Framework class libraries, which are held in namespaces.
Support for multiple programming languages. Having a set of libraries and a runtime is
good, but neither one of them is useful if you can‟t write programs to take advantage of them. In
order to do that, you need to use some programming language with a compiler that is runtime-
aware. Microsoft currently lists over twenty different languages with which it will be possible to
write software that targets the CLR. Microsoft itself ship support for five languages with the
SDK: C#, Visual Basic.NET, IL, C++, and JScript.NET. Of these, C# and Visual Basic.NET are
likely to be the languages most often used to develop software for this new platform. Any
language that conforms to the Common Language Specification (CLS) can run with the
common language runtime. Relying on the common language runtime, code compiled with
compilers of .NET based languages can interoperate. All .NET-based languages also access the
same libraries.
Features of .NET Framework
• It is a platform neutral framework.
• It is a layer between the operating system and the programming language.
• It supports many programming languages, including VB.NET, C# etc.
• .NET provides a common set of class libraries, which can be accessed from any .NET based
programming language. There will not be separate set of classes and libraries for each language.
If you know anyone .NET language, you can write code in any .NET language.

• In future versions of Windows, .NET will be freely distributed as part of operating system and
users will never have to install .NET separately.
Common Language Runtime (CLR) in C#

The Common Language Runtime (CLR) is a component of the Microsoft .NET Framework that
manages the execution of .NET applications. It is responsible for loading and executing the code written
in various .NET programming languages, including C#, VB.NET, F#, and others.
When a C# program is compiled, the resulting executable code is in an intermediate language
called Common Intermediate Language (CIL) or Microsoft Intermediate Language (MSIL). This code is
not machine-specific, and it can run on any platform that has the CLR installed. When the CIL code is
executed, the CLR compiles it into machine code that can be executed by the processor.
The CLR provides many services to .NET applications, including memory management, type
safety, security, and exception handling. It also provides Just-In-Time (JIT) compilation, which compiles
the CIL code into machine code on the fly as the program runs, optimizing performance.
Additionally, the CLR provides a framework for developing and deploying .NET applications,
including a set of libraries, called the .NET Framework Class Library, which provides access to a wide
range of functionality, such as input/output operations, networking, database connectivity, and user
interface design.
Overall, the CLR is a critical component of the .NET Framework and is responsible for ensuring that
.NET applications are executed in a safe, secure, and efficient manner, making it a fundamental aspect of
C# programming.
CLR is the basic and Virtual Machine component of the .NET Framework. It is the run-time
environment in the .NET Framework that runs the codes and helps in making the development process
easier by providing the various services. Basically, it is responsible for managing the execution of .NET
programs regardless of any .NET programming language. Internally, CLR implements the VES(Virtual
Execution System) which is defined in the Microsoft‟s implementation of the CLI(Common Language
Infrastructure).
The code that runs under the Common Language Runtime is termed as the Managed Code. In
other words, you can say that CLR provides a managed execution environment for the .NET programs by
improving the security, including the cross language integration and a rich set of class libraries, etc. CLR
is present in every .NET framework version. Below table illustrate the CLR version in .NET framework.

CLR Versions .NET Framework Versions

1.0 1.0

1.1 1.1

2.0 2.0

2.0 3.0

2.0 3.5

4 4
CLR Versions .NET Framework Versions

4 4.5(also 4.5.1 & 4.5.2)

4 4.6(also 4.6.1 & 4.6.2)

4 4.7(also 4.7.1 & 4.7.2)


Below diagram illustrate how CLR is associated with the operating system/hardware along with the class
libraries. Here, the runtime is actually CLR.

Role of CLR in the execution of a C# program


 Suppose you have written a C# program and save it in a file which is known as the Source Code.
 Language specific compiler compiles the source code into the MSIL (Microsoft Intermediate
Language) which is also known as the CIL (Common Intermediate Language) or IL (Intermediate
Language) along with its metadata. Metadata includes all the types, actual implementation of each
function of the program. MSIL is machine-independent code.
 Now CLR comes into existence. CLR provides the services and runtime environment to the MSIL
code. Internally CLR includes the JIT (Just-In-Time) compiler which converts the MSIL code to
machine code which further executed by CPU. CLR also uses the .NET Framework class libraries.
Metadata provides information about the programming language, environment, version, and class
libraries to the CLR by which CLR handles the MSIL code. As CLR is common so it allows an
instance of a class that written in a different language to call a method of the class which written in
another language.
Elements of the .NET Framework.
 CLR (Common Language Runtime): It is a common managed environment where all the .net
programs run. Supports multiple languages and has the garbage collector.
 .Net Framework Class Libraries: For each source code compiler (VB.NET, C#.NET, etc.), there
is a minimum set of coding standards that must be met. The minimum set of coding standards that
must be met to compile .NET code into MSIL code is known as CLS - Common Language
Specification. The role of the Common Language Specification is to ensure that all generated
code (MSIL) that meets the minimum set of coding standards can operate successfully within the
.NET framework. THE CTS (Common Type System) handles conversion of programming-
language data types into .NET compatible (MSIL) data types. The implicit benefit of the CTS is
the reduction of development time when attempting to coordinate data types between two sets of
different programming-language code.
 Data and XML: Support for disconnected programming model and XML.
 XML webservices: creating webservices for distributed architecture.
 Webforms: Provides support and functionality for Web based UI.
 Windows forms: Provides support and functionality for Windows based UI.

What is Garbage Collection in .NET Framework?


When a dot net application runs, lots of objects are created. At a given point in time, it is possible
that some of those objects are not used by the application. Garbage Collector in .NET Framework is
nothing but a Small Routine or you can say it‟s a Background Process Thread that runs periodically and
try to identify what objects are not being used currently by the application and de-allocates the memory of
those objects.
So, Garbage Collector is nothing but, it is a feature provided by CLR which helps us to clean or
destroy unused managed objects. Cleaning or destroying those unused managed objects basically reclaim
the memory.
Note: The Garbage Collector will destroy only the unused managed objects. It does not clean
unmanaged objects.
Managed and Unmanaged objects in .NET Framework:
Let us understand Managed and Unmanaged objects. Whenever we create any EXE (i.e. console
application, windows application, etc.) or web application (i.e. ASP.NET MVC, Web API, ASP.NET,
Class Library, etc.) in .NET Framework using visual studio and using any .NET supported programming
language such as C#, VB, F#, etc., then these applications are run completely under the control of CLR
(Common Language Runtime). That means, if your applications have unused objects, then CLR will
clean those objects using Garbage Collector.

Common Type System


In Microsoft's .NET Framework, the Common Type System (CTS) is a standard that specifies
how type definitions and specific values of types are represented in computer memory. It is intended to
allow programs written in different programming languages to easily share information. As used
in programming languages, a type can be described as a definition of a set of values (for example, "all
integers between 0 and 10"), and the allowable operations on those values (for example, addition and
subtraction).
The specification for the CTS is contained in Ecma standard 335, "Common Language
Infrastructure (CLI) Partitions I to VI." The CLI and the CTS were created by Microsoft, and
the Microsoft .NET framework is an implementation of the standard.

Functions of the Common Type System

 To establish a framework that helps enable cross-language integration, type safety, and high
performance code execution.
 To provide an object-oriented model that supports the complete implementation of many
programming languages.
 To define rules that languages must follow, which helps ensure that objects written in different
languages can interact with each other.
 The CTS also defines the rules that ensure that the data types of objects written in various languages
are able to interact with each other.
 The CTS also specifies the rules for type visibility and access to the members of a type, i.e. the CTS
establishes the rules by which assemblies form scope for a type, and the Common Language Runtime
enforces the visibility rules.
 The CTS defines the rules governing type inheritance, virtual methods and object lifetime.
 Languages supported by .NET can implement all or some common data types…
When rounding fractional values, the halfway-to-even ("banker's") method is used by default,
throughout the Framework. Since version 2, "Symmetric Arithmetic Rounding" (round halves away from
zero) is also available by programmer's option.[1]

 it is used to communicate with other languages

Type categories
The common type system supports two general categories of types:
Value types
Value types directly contain their data, and instances of value types are either allocated on
the stack or allocated inline in a structure. Value types can be built-in (implemented by the
runtime), user-defined, or enumerations.
Reference types
Reference types store a reference to the value's memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types. The type of a
reference type can be determined from values of self-describing types. Self-describing types are
further split into arrays and class types. The class types are user-defined classes, boxed value
types, and delegates.

Common Language Integration in .Net Framework

Introduction:

CLI (Common Language Integration) is an important concept in .Net Framework. As


you, .Net supports multiple languages; more than 100 In Visual Studio 2010. Now you want to
add two DLLs (dynamic Link Libraries) to your project but one DLL is in C# language and other
is in VB Language and when we use both languages together we are getting the same output
without any error. So this is the concept of CLI. Now we see how does it happen?
Summary:
Open two different Class Libraries such as ClassLibrary1 and ClassLibrary2, one should
be in C# and other should be in any language Like VB. OK.

User and Program Interface


The .NET framework provides the following tools for manag1ng user and application interfaces:
• Windows forms
• Web Forms
• Console Applications
• Web Services
These tools enable users to develop user-friendly desktop-based as well as web-based
applications using a wide variety of languages on the .NET platform.
 Window Forms
 Web Forms
 Console Application

Window Forms
Windows forms (also called Win Forms) ate used to create GUI-for Windows desktop
applications. The idea of Win Form has been borrowed from Windows Foundation Classes
(WFC) which was used for Visual J++. Win Form provide an integrated and unified way of
developing -GUI. It has a rich variety of windows controls and user interface support.
Numerous classes and functions were used by programmers to handle GUT. MFC in
VC++, direct API in C++ and VB Forms Engine in VB are just a few examples of different
ways of handling GUI.
Simply Win Form is just another group of wrapper classes that deal specifically with
GUI. Win Form classes encapsulate the Windows Graphical APIs. Now the programmers
would not need to use the Windows Graphical APIs directly; and since Win Form has been
made a part of .NET. Class Framework; all the programming languages would use the same
Win Form classes. This would rid the programmers of the need to learn different· GUI
classes/tools. Win Forms in the part of the namespace System Winforms.
With Win Forms we can make a single user interface, and use it in VC++, VB, and C #. Using
Visual Studio. NET simply designs the GUI, by dragging the controls on a form
(something that all VC++ and VB programmers are well familiar with). Now you can use the
same form either in VB, VC++ or in C#. And this is all made possible because Visual
Studio.NET uses the System. Winforms namespace to draw the GUI. And any language that has
the appropriate CLS compliance can use this form directly.
Web Forms
Just as the Win Forms provide a unified way of developing GUI for desktop application,
the Web Forms provide similar tool for web applications. Web Forms has been introduced in
.NET as a part of ASP.NET. Web‟ Forms are a form engine that provides a browser-based user
interface.
To appreciate Web Forms you may consider how GUI is rendered in current Web
applications. The GUI is rendered by using HTML tags. (e.g. <input type=text name=editboxl
maxlength=10 size=10 >, will draw an edit box on the web page) Web Forms can also have the
intelligence to use HTML, DHTML, and WML etc. to draw the controls on the web page based
on the browser‟s capabilities. Web Forms can also incorporate the logic behind these controls.
It‟s like hooking up the code to a GUI control. Just like in your VB application, you can
associate a code with a button on the web page; this code will be run on the server when the
button is pressed. This is in contrast to the scripts that run on the clients when a button is
pressed.
This approach is different to the Java approach. In Java a programmer can simulate this
functionality through JavaScript and Servlets. But with Web forms this is done transparently.
Web Forms consist of two parts – a template, which contains HTML-based
layout information for all the GUI elements and a Component which contains all the logic to be
hooked to the controls or GUI elements. This provides a neat presentation layer and application
logic layer separation.
The GUI will be rendered on the client side, while the code that has been hooked to the GUI
elements will run on the server side (very „much likes a button being pressed on a JSP and a
Servlets being called in response. But with Win Forms this has been made extremely easy). The
incorporation of Web Forms in ASP.NET is an attempt to take ASP to a new level where it can
seriously challenge JSP.
One of the obvious disadvantages of ASP over Java was that there was that an ASP code was a
maintenance nightmare. While a Java programmer can use Java Beans, Tags and also Servlets
to achieve presentation and business layer separation – no such mechanism was present to an
ASP programmer. With ASP.NET Microsoft „has provided such presentation business, layer
separation – by introducing the concept of Web Forms:
1. ASP.NET Web Forms provide an easy and to build dynamic Web UI.
2. ASP.NET Web Forms pages can target any browser client (there are no script library or.
cookie requirements).
3. ASP.NET Web Forms pages· provide syntax compatibility with existing ASP pages.
4. ASP.NET server controls provide an easy way to encapsulate common functionality.
Console Application
Console applications are command line oriented applications that allow user to read
characters from the· console, write characters to the console.
Console applications are typically designed without graphical user interface and are compiled in
a stand-alone executable file.
A console application is run from the command line with input and output information being
exchanged between the command prompt and the running application. Because information can
be written to and read from .the console window, this makes the console application a great way
to learn new programming techniques without having to be concerned with the user interface.

Web Services
A web service is an extension of ActiveX. Those programmers, who have used ASP and
JSP both, know the apparent shortcomings of ASP. JSP has been enriched with the concepts of
Beans. And Tags. ASP equivalent for Beans and Tags was ActiveX Controls. and ActiveX
automation servers. Let me take a minute to explain this point a bit further. Web Services
is NOT a Microsoft proprietary standard. It is a W3Consortium standard, and has been
developed by Microsoft, IBM and many other big names of the industry.
Functions are of two types. The ASP built-in functions and the programmer defined
implemented functions. In order to use the built in functions you just need to pass the
appropriate parameters and make a simple call to these functions. The functions are
implemented by the ASP itself. The string manipulation functions, Number conversion
functions are an, example of built in functions.
The user-defined functions are the functions that are defined and implemented by the
programmer. A programmer can either write these functions in the same asp file or can write
them in another file. If the function code resides in the same asp file then the programmer can
directly call that function. In case the function resides in another file, say “func.asp”; then the
programmer needs to include that file by writing a statement like <!- #include file=”func.asp” -
>; and now the programmer can use the function. The programmers can also make ActiveX
automation servers, and call various functions of these ActiveX servers, But one limitation is
very obvious – no matter which type of function you use, the function MUST physically reside
on the same machine. For example your ActiveX automation server must be implemented either
as a .dll or as an .exe and then must also be registered in Windows Registry before an asp code
can call its functions.
In a world where the Intemet has become not only a necessity but also a way of life – it is
obvious that this limitation is a strong one; Microsoft‟s answer to this problem
is “Web Services”. The idea goes something like this:
1. The Web service provider develops a useful function(s), and publish/advertise it. The
Web Service provider uses Web Service Description Language (WSDL) standard to describe the
interface of the function(s). This is much like the Type Libraries (TLB) and Object Description
Language files (ODL) that needs to be generated with the ActiveX automation servers.
2. The programmer/client who needs the function does a lookup by using a process called
– Web Service Discovery or SOAP Discovery (also called DISCO for Web Service Discovery)
3. The Actual communication between the client program and the web service takes place
through a protocol called Simple Object Access Protocol (SOAP) -SOAP is an XML based light
weight protocol used for communication in a decentralized distributed environment.

What is Optimization?

The word Optimization is derived from the Latin word Optimal which means the best.
Optimization is a methodology of making a system or decision fully perfect, functional, and
effective.

Now, what is code Optimization?

In terms of code, Optimization is the process of modifying code in such a way that
enhances its performance, improves code quality, and makes it as efficient as possible. It
requires an aspect of writing an efficient C# .Net -based application.

Need of Optimized code

A program should be optimized so that it:

 Becomes a smaller size.


 Consumes less memory.
 Faster execution.
 Performs fewer input/output operations.

You might also like