Unit 1 1
Unit 1 1
The .NET Framework is a software development platform that was introduced by Microsoft in the
late 1990 under the NGWS. On 13 February 2002, Microsoft launched the first version of the .NET
Framework, referred to as the .NET Framework 1.0.
In this section, we will understand the .NET Framework, characteristics, components, and
its versions.
It is a virtual machine that provide a common platform to run an application that was built using the
different language such as C#, VB.NET, Visual Basic, etc. It is also used to create a form based,
console-based, mobile and web-based application or services that are available in Microsoft
environment. Furthermore, the .NET framework is a pure object oriented, that similar to the Java
language. But it is not a platform independent as the Java. So, its application runs only to the windows
platform.
The main objective of this framework is to develop an application that can run on
the windows platform. The current version of the .Net framework is 4.8.
Note: The .NET Framework is not only a language, but it is also a software and language
neutral platform.
Components of .NET Framework
It is an important part of a .NET framework that works like a virtual component of the .NET
Framework to executes the different languages program like c#, Visual Basic, etc. A CLR also helps
to convert a source code into the byte code, and this byte code is known as CIL (Common
Intermediate Language) or MSIL (Microsoft Intermediate Language). After converting into a byte
code, a CLR uses a JIT compiler at run time that helps to convert a CIL or MSIL code into the
machine or native code.
It is a program execution engine that loads and executes the program. It converts the program
into native code. It acts as an interface between the framework and operating system
• Suppose we have written a C# program and save it in a file.
• Language specific compiler compiles the source code into the MSIL(Microsoft Intermediate
Language) which is also know as the CIL(Common Intermediate
Language) or IL(Intermediate Language) along with its metadata.
• Metadata includes the 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.
• Common Language Specification (CLS) : It is responsible for converting the different .NET
programming language syntactical rules and regulations into CLR understandable format.
Basically, it provides the Language Interoperability.
• Common Type System (CTS) :Every programming language has its own data type system, so
CTS is responsible for understanding all the data type of system.
• Garbage Collection (GC): It is used to provide the Automatic Memory Management feature.
• Just In – Time Compiler (JIT) : It is responsible for converting the CIL(Common
Intermediate Language) into machine code or native code using the Common Language
Runtime environment.
It specifies a standard that represent what type of data and value can be defined and managed in
computer memory at runtime. A CTS ensures that programming data defined in various languages
should be interact with each other to share information. For example, in C# we define data type as int,
while in VB.NET we define integer as a data type.
The language interoperability, and .NET Class Framework, are not possible without all the language
sharing the same data types. What this means is that an “int” should mean the same in VB, VC++, C#
and all other .NET compliant languages. Same idea follows for all the other data types. This is
achieved through introduction of Common Type System (CTS).
Common type system (CTS) is an important part of the runtimes support for cross language
integration. The common type system performs the following functions:
• Establishes a framework that enables cross-language integration, type safety, and high performance
code execution.
• Provides an object-oriented model that supports the complete implementation of many programming
languages.
The base class library has a rich collection of libraries features and functions that help to implement
many programming languages in the .NET Framework, such as C #, F #, Visual C ++, and more.
Furthermore, BCL divides into two parts:
It is a subset of common type system (CTS) that defines a set of rules and regulations which should be
followed by every language that comes under the .net framework. In other words, a CLS language
should be cross-language integration or interoperability. For example, in C# and VB.NET language,
the C# language terminate each statement with semicolon, whereas in VB.NET it is not end with
semicolon, and when these statements execute in .NET Framework, it provides a common platform to
interact and share information with each other.
A .NET assembly is the main building block of the .NET Framework. It is a small unit of code that
contains a logical compiled code in the Common Language infrastructure (CLI), which is used for
deployment, security and versioning. It defines in two parts (process) DLL and library (exe)
assemblies. When the .NET program is compiled, it generates a metadata with Microsoft Intermediate
Language, which is stored in a file called Assembly.
It provides the various system functionality in the .NET Framework, that includes classes, interfaces
and data types, etc. to create multiple functions and different types of application such as desktop,
web, mobile application, etc. In other words, it can be defined as, it provides a base on which various
applications, controls and components are built in .NET Framework.
Key Components of FCL
1. Object type
2. Implementation of data structure
3. Base data types
4. Garbage collection
5. Security and database connectivity
6. Creating common platform for window and web-based application
In the common language runtime (CLR), the garbage collector (GC) serves as an automatic
memory manager. The garbage collector manages the allocation and release of memory for an
application. Therefore, developers working with managed code don't have to write code to
perform memory management tasks. Automatic memory management can eliminate common
problems such as forgetting to free an object and causing a memory leak or attempting to
access freed memory for an object that's already been freed.
Benefits
Reclaims objects that are no longer being used, clears their memory, and keeps the memory
available for future allocations. Managed objects automatically get clean content to start with,
so their constructors don't have to initialize every data field.
Provides memory safety by making sure that an object can't use for itself the memory
allocated for another object.
Characteristics of .NET Framework
- This library system functionality and is the foundation of .NET Framework applications,
components, and controls are built.
- The .NET base class library exists in order to encapsulate a huge number of common functions and
makes them easily accessible to the developer.
- It provides the functionality like ADO.NET, XML, Threading, IO, Security, Diagnostics, Resources,
Globalization, collections etc.
- The .Net base class library provides namespaces which are frequently used, some of them are as
follows:
Namespaces Description
System It contains fundamental classes and base classes that define commonly-
used value and reference data types, events and event handlers, interfaces,
attributes and processing exceptions.
System.Activities It contains all the classes necessary to create and work with activities in
Windows Workflow Foundation.
System.Collections It contains types that define various standard, specialized and generic
collection objects.
System.Configuration It contains types that define various standard, specialized and generic
collection objects.
System.Data It contains classes for accessing and managing data from diverse sources.
System.IO It contains types that support input and output, including the ability to read
and write data to streams either synchronously or asynchronously.
System.Printing It contains types that support printing. It provides access to the properties
of print system objects.
System.Runtime It contains types that support an application's interaction with the common
language runtime.
System.Security It contains classes that represent the .Net framework security system and
permissions.
Namespaces
Namespaces are used to organize the classes. It helps to control the scope of methods and classes in
larger .Net programming projects. In simpler words you can say that it provides a way to keep one
set of names(like class names) different from other sets of names. The biggest advantage of using
namespace is that the class names which are declared in one namespace will not clash with the same
class names declared in another namespace. It is also referred as named group of classes having
common features. The members of a namespace can be namespaces, interfaces, structures,
and delegates.
Defining a Namespace
To define a namespace in C#, we will use the namespace keyword followed by the name of the
namespace and curly braces containing the body of the namespace as follows:
Syntax:
namespace name_of_namespace {
}
example
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Namespace!");
}
}
}
Example:
// defining the namespace name1
namespace name1
{
// C1 is the class in the namespace name1
class C1
{
// class code
}
}
example of namespace in C# where one namespace program accesses another namespace
program
using System;
namespace First {
public class Hello
{
public void sayHello()
{
Console.WriteLine("Hello First Namespace");
}
}
}
namespace Second
{
public class Hello
{
public void sayHello() { Console.WriteLine("Hello Second Namespace"); }
}
}
public class TestNamespace
{
public static void Main()
{
First.Hello h1 = new First.Hello();
Second.Hello h2 = new Second.Hello();
h1.sayHello();
h2.sayHello();
}
}
Output:
OLE Technology: OLE (Object Linking and Embedding) is one of the technologies of Microsoft’s
component document. Basically, its main purpose is to link elements from different applications
with each other.
COM Technology: The technology of the Microsoft Windows family of the operating system,
Microsoft COM (Common Object Model) enables various software components to communicate.
COM is mostly used by developers for various purposes like creating reusable software
components, linking components together to build applications, and also taking advantage of
Windows services. The objects of COM can be created with a wide range of programming
languages.
.NET Technology: .NET technology of collection or set of technologies to develop windows and
web applications. The technology of .Net is developed by Microsoft and was launched in Feb. 2002,
by basic definition, Microsoft’s new Internet Strategy. It was originally called NGWS (Next
Generation Web Services). It is considered to be one of the most powerful, popular, and very useful
Internet Technology available today.
11 Programming Languages which are designed and developed by Microsoft are:
• C#.NET
• VB.NET
• C++.NET
• J#.NET
• F#.NET
• JSCRIPT.NET
• WINDOWS POWERSHELL
• IRON RUBY
• IRON PYTHON
• C OMEGA
• ASML(Abstract State Machine Language)
Important Points:
• Visual Studio is the development tool that is used to design and develop .NET
applications. For using Visual Studio, the user has to first install the .NET framework
on the system.
• In the older version of Windows OS like XP SP1, SP2, or SP3, the .NET framework
was integrated with the installation media.
• Windows 8, 8.1, or 10 do not provide a pre-installed version 3.5 or later of .NET
Framework. Therefore, a version higher than 3.5 must be installed either from a
Windows installation media or from the Internet on demand. Windows update will give
recommendations to install the .NET framework.
The Microsoft Intermediate Language (MSIL), also known as the Common Intermediate Language
(CIL) is a set of instructions that are platform independent and are generated by the language-specific
compiler from the source code. The MSIL is platform independent and consequently, it can be
executed on any of the Common Language Infrastructure supported environments such as the
Windows .NET runtime.
The MSIL is converted into a particular computer environment specific machine code by the JIT
compiler. This is done before the MSIL can be executed. Also, the MSIL is converted into the
machine code on a requirement basis i.e. the JIT compiler compiles the MSIL as required rather than
the whole of it.
Execution process in Common Language Runtime (CLR): The execution process that includes the
creation of the MSIL and the conversion of the MSIL into machine code by the JIT compiler is given
as follows:
• The source code is converted into the MSIL by a language-specific compiler in the
compile time of the CLR. Also, along with the MSIL, metadata is also produced in the
compilation. The metadata contains information such as the definition and signature of
the types in the code, runtime information, etc.
• A Common Language Infrastructure (CLI) assembly is created by assembling the MSIL.
This assembly is basically a compiled code library that is used for security, deployment,
versioning, etc. and it is of two types i.e. process assembly (EXE) and library assembly
(DLL).
• The JIT compiler then converts the Microsoft Intermediate Language(MSIL) into the
machine code that is specific to the computer environment that the JIT compiler runs on.
The MSIL is converted into the machine code on a requirement basis i.e. the JIT compiler
compiles the MSIL as required rather than the whole of it.
• The machine code obtained using the JIT compiler is then executed by the processor of
the computer.
Example: The MSIL is generated by the language specific compiler from the source code given
below. To understand the MSIL in detail, simple C# source code with the class Demo that prints hello
world is given as follows:
using System;
public class Demo {
public static void Main()
{
Console.WriteLine("hello world");
}
}
In the above MSIL, there are opcodes that are one or two bytes long. The base class declarations from
which all other classes are inherited are contained in the mscorlib.dll. In the method Main(), the
instruction ldstr loads the string “hello world” on the stack. Then the
static System.Console.Writeline function is called and the string is popped from the stack. Finally, the
ret instruction signals the end of the function call.
Then the .ctor() statement implies a default constructor without parameters for the class Demo. This
constructor is automatically created by the compiler for the non-static class Demo. The call instruction
passes the base object constructor and the ret instruction signals the end of the function call.
- Assembly Manifest describes the relationship and dependencies of the components in the assembly.
- The versioning information, scope information and the security permissions are required by the
assembly.
- An Assembly data like version, scope, security information (strong name),etc is stored in manifest.
- The assembly manifest also contains a reference to the resource and classes.
- The assembly manifest of an assembly is stored in either an .exe or a .dll with Microsoft
intermediate language (MSIL) code.
- It contains a collection of data that describes how the elements in the assembly relate to each other.
Where is it stored?
- It can be stored in Portable Executable(PE) file (.exe or .dll) with Microsoft Intermediate
Language(MSIL) code.
- You can add or change some information in the Assembly Manifest by using assembly attributes in
your code.
- You can view the manifest information for any managed DLL using ILDasm.
It performs following functions:
- It provides a level of indirection between consumers of the assembly and the assemblies
implementation details.
Namespaces are used to organize the classes. It helps to control the scope of methods and classes in
larger .Net programming projects. In simpler words you can say that it provides a way to keep one
set of names(like class names) different from other sets of names. The biggest advantage of using
namespace is that the class names which are declared in one namespace will not clash with the same
class names declared in another namespace. It is also referred as named group of classes having
common features. The members of a namespace can be namespaces, interfaces, structures,
and delegates.
Defining a Namespace
To define a namespace in C#, we will use the namespace keyword followed by the name of the
namespace and curly braces containing the body of the namespace as follows:
Syntax:
namespace name_of_namespace {
Nested Namespaces
You can also define a namespace into another namespace which is termed as the nested namespace.
To access the members of nested namespace user has to use the dot(.) operator.
For example, Generic is the nested namespace in the collections namespace
as System.Collections.Generic
Syntax:
namespace name_of_namespace_1
{
// Member declarations & definitions
namespace name_of_namespace_2
{
// Member declarations & definitions
.
.
}
}
C# .NET
We can also name various tech differences; for example, local variables are automatically
initialized in .NET but not in C#; a specific base class constructor is used in the .NET
framework but lacks in C#; and many other different things.
Review questions;
1. Explain the following in detail
• CTS (Common Type System)
• BCL (Base Class Library)
• CLS (Common Language Specification)
• FCL (Framework Class Library)