0% found this document useful (0 votes)
48 views19 pages

Dot Net Unit - 1

The document discusses the .NET framework, which was developed by Microsoft as a development platform for building and running Windows applications. It allows developers to create both web and desktop applications using languages like C# and VB.NET. The framework includes common language runtime, class libraries and components that provide features like memory management, security, and simplified deployment.

Uploaded by

Rit9t8ri Viotur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views19 pages

Dot Net Unit - 1

The document discusses the .NET framework, which was developed by Microsoft as a development platform for building and running Windows applications. It allows developers to create both web and desktop applications using languages like C# and VB.NET. The framework includes common language runtime, class libraries and components that provide features like memory management, security, and simplified deployment.

Uploaded by

Rit9t8ri Viotur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Unit-1

Introduction to DOT NET Framework


Before DOT NET Framework let us first discuss what is COM and what problems we face in COM.
What is COM?
COM stands for Component Object Model. The COM is one of Microsoft Technologies. Using this technology we
can develop windows applications as well as web applications. In earlier COM, VB is the programming language
that is used to implement windows application and ASP is used to implement web applications.
What are the disadvantages of COM?
The major two disadvantages of COM is
1. Incomplete object-oriented programming means it will not support all the features of OOPs.
2. Platform dependent means COM applications can run on only Windows OS.
To overcome the above problems, the DOT NET Framework comes into the picture.

What .NET Represents?


NET stands for Network Enabled Technology. In .NET, dot (.) refers to object-oriented and NET refers to the internet.
So the complete .NET means through object-oriented we can implement internet-based applications.
What is a Framework?
A framework is software. Or you can say a framework is a collection of many small technologies integrated together
to develop applications that can be executed anywhere.

What is .Net Framework?

.Net Framework is a software development platform developed by Microsoft for building and running Windows
applications. The .Net framework consists of developer tools, programming languages, and libraries to build
desktop and web applications. It is also used to build websites, web services, and games.

The .Net framework was meant to create applications, which would run on the Windows Platform. The first version
of the .Net framework was released in the year 2002. The version was called .Net framework 1.0. The Microsoft
.Net framework has come a long way since then, and the current version is .Net Framework 4.7.2.

The Microsoft .Net framework can be used to create both - Form-based and Web-based applications. Web
services can also be developed using the .Net framework.

The framework also supports various programming languages such as Visual Basic and C#. So developers can
choose and select the language to develop the required application.

.Net Framework Architecture

.Net Framework Architecture is a programming model for the .Net platform that provides an execution
environment and integration with various programming languages for simple development and deployment of
various Windows and desktop applications. It consists of class libraries and reusable components.

The basic architecture of the .Net framework is as shown below.


.Net Framework Architecture

.NET Components

The architecture of .Net framework is based on the following key components;

1. Common Language Runtime

The "Common Language Infrastructure" or CLI is a platform in .Net architecture on which the .Net programs are
executed.

The CLI has the following key features:

• Exception Handling - Exceptions are errors which occur when the application is executed.

Examples of exceptions are:

o If an application tries to open a file on the local machine, but the file is not present.
o If the application tries to fetch some records from a database, but the connection to the database is
not valid.
• Garbage Collection - Garbage collection is the process of removing unwanted resources when they are no
longer required.

Examples of garbage collection are

o A File handle which is no longer required. If the application has finished all operations on a file, then
the file handle may no longer be required.
o The database connection is no longer required. If the application has finished all operations on a
database, then the database connection may no longer be required.
• Working with Various programming languages –

1. Language - The first level is the programming language itself, the most common ones are VB.Net and C#.
2. Compiler – There is a compiler which will be separate for each programming language. So underlying the
VB.Net language, there will be a separate VB.Net compiler. Similarly, for C#, you will have another
compiler.
3. Common Language Interpreter – This is the final layer in .Net which would be used to run a .net program
developed in any programming language. So the subsequent compiler will send the program to the CLI
layer to run the .Net application.
2. Class Library

The .NET Framework includes a set of standard class libraries. A class library is a collection of methods and
functions that can be used for the core purpose.

For example, there is a class library with methods to handle all file-level operations. So there is a method which can
be used to read the text from a file. Similarly, there is a method to write text to a file.

Most of the methods are split into either the System.* or Microsoft.* namespaces. (The asterisk * just means a
reference to all of the methods that fall under the System or Microsoft namespace)

A namespace is a logical separation of methods. We will learn these namespaces more in detail in the subsequent
chapters.

3. Languages

The types of applications that can be built in the .Net framework is classified broadly into the following categories.

• WinForms – This is used for developing Forms-based applications, which would run on an end user
machine. Notepad is an example of a client-based application.
• ASP.Net – This is used for developing web-based applications, which are made to run on any browser such
as Internet Explorer, Chrome or Firefox.
o The Web application would be processed on a server, which would have Internet Information
Services Installed.
o Internet Information Services or IIS is a Microsoft component which is used to execute
an Asp.Net application.
o The result of the execution is then sent to the client machines, and the output is shown in the
browser.
• ADO.Net – This technology is used to develop applications to interact with Databases such as Oracle or
Microsoft SQL Server.

Microsoft always ensures that .Net frameworks are in compliance with all the supported Windows operating
systems.

.Net Framework Design Principle

Now in this .Net Architecture tutorial, we will learn the design priciples of .Net framework. The following design
principles of the .Net framework is what makes it very relevant to create .Net based applications.
1. Interoperability - The .Net framework provides a lot of backward support. Suppose if you had an
application built on an older version of the .Net framework, say 2.0. And if you tried to run the same
application on a machine which had the higher version of the .Net framework, say 3.5. The application
would still work. This is because with every release, Microsoft ensures that older framework versions gel
well with the latest version.
2. Portability- Applications built on the .Net framework can be made to work on any Windows platform. And
now in recent times, Microsoft is also envisioning to make Microsoft products work on other platforms,
such as iOS and Linux.
3. Security - The .NET Framework has a good security mechanism. The inbuilt security mechanism helps in
both validation and verification of applications. Every application can explicitly define their security
mechanism. Each security mechanism is used to grant the user access to the code or to the running program.
4. Memory management - The Common Language runtime does all the work or memory management. The
.Net framework has all the capability to see those resources, which are not used by a running program. It
would then release those resources accordingly. This is done via a program called the "Garbage Collector"
which runs as part of the .Net framework.

The garbage collector runs at regular intervals and keeps on checking which system resources are not
utilized, and frees them accordingly.

5. Simplified deployment - The .Net framework also have tools, which can be used to package applications
built on the .Net framework. These packages can then be distributed to client machines. The packages
would then automatically install the application.

Important Points:
• Visual Studio is the development tool that is used to design and develop the .NET applications. For using
Visual Studio, the user has to first install the .NET framework on the system.
• 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.

Common Language Runtime (CLR)


The heart of .NET Framework is a run-time environment called the common language runtime (CLR). The CLR
manages the life cycle and executes .NET applications (code). It also provides services that make the development
process easier.

CLR is the basic and Virtual Machine component of the .NET Framework. It is the run-time enviornment 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 enviornment for the .NET programs by improving the security,
including the cross language integration and a rich set of class libraries etc.
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 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. 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.

Main Components of CLR

As the word specify, Common means CLR provides a common runtime or execution environment as there are more
than 60 .NET programming languages.
Main components of CLR:
• Common Language Specification (CLS)
• Common Type System (CTS)
• Garbage Collection (GC)
• Just In – Time Compiler (JIT)
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. Language Interoperability means
to provide the execution support to other programming languages also in .NET framework.
Language Interoperability can be achieved in two ways :
i. Managed Code: The MSIL code which is managed by the CLR is known as the Managed Code. For managed
code CLR provides three .NET facilities:

• CAS(Code Access Security)


• Exception Handling
• Automatic Memory Management.
ii. Unmanaged Code: Before .NET development the programming language like .COM Components & Win32
API do not generate the MSIL code. So these are not managed by CLR rather managed by Operating System.
Common Type System (CTS):
Every programming language has its own data type system, so CTS is responsible for understanding all the data
type systems of .NET programming languages and converting them into CLR understandable format which will be
a common format.
There are 2 Types of CTS that every .NET programming language have :
1. Value Types: Value Types will store the value directly into the memory location. These types work with stack
mechanism only. CLR allows memory for these at Compile Time.
2. Reference Types: Reference Types will contain a memory address of value because the reference types won’t
store the variable value directly in memory. These types work with Heap mechanism. CLR allots memory for
these at Runtime.
Garbage Collector:
It is used to provide the Automatic Memory Management feature. If there was no garbage collector, programmers
would have to write the memory management codes which will be a kind of overhead on programmers.
JIT(Just In Time Compiler):
It is responsible for converting the CIL(Common Intermediate Language) into machine code or native code using
the Common Language Runtime environment.

Benefits of CLR:
• It improves the performance by providing a rich interact between programs at run time.
• Enhance portability by removing the need of recompiling a program on any operating system that supports it.
• Security also increases as it analyzes the MSIL instructions whether they are safe or unsafe. Also, the use of
delegates in place of function pointers enhance the type safety and security.
• Support automatic memory management with the help of Garbage Collector.
• Provides cross-language integration because CTS inside CLR provides a common standard that activates the
different languages to extend and share each other’s libraries.
• Provides support to use the components that developed in other .NET programming languages.
• Provide language, platform, and architecture independence.
• It allows easy creation of scalable and multithreaded applications, as the developer has no need to think about
the memory management and security issues.

.NET Program Execution Process


Code Execution Process
The Code Execution Process involves the following two stages:

1. Compiler time process.


2. Runtime process.

1. Compiler time process

1. The .Net framework has one or


more language compilers, such
as Visual Basic, C#, Visual
C++, JScript, or one of many
third-party compilers such as an
Eiffel, Perl, or COBOL
compiler.
2. Anyone of the compilers
translates your source code into
Microsoft Intermediate Language (MSIL) code.
3. For example, if you are using the C# programming language to develop an application, when you compile
the application, the C# language compiler will convert your source code into Microsoft Intermediate
Language (MSIL) code.
4. In short, VB.NET, C#, and other language compilers generate MSIL code. (In other words, compiling
translates your source code into MSIL and generates the required metadata.)
5. Currently "Microsoft Intermediate Language" (MSIL) code is also known as the "Intermediate Language"
(IL) Code or "Common Intermediate Language" (CIL) Code.

SOURCE CODE -----.NET COMLIPER------> BYTE CODE (MSIL + META DATA)

2. Runtime process.

1. The Common Language Runtime (CLR) includes a JIT compiler for converting MSIL to native code.
2. The JIT Compiler in CLR converts the MSIL code into native machine code that is then executed by the OS.
3. During the runtime of a program, the "Just in Time" (JIT) compiler of the Common Language Runtime
(CLR) uses the Metadata and converts Microsoft Intermediate Language (MSIL) into native code.

BYTE CODE (MSIL + META DATA) ----- Just-In-Time (JIT) compiler------> NATIVE CODE

Notes:
When you compile a C# application or any application written in a CLS-compliant language, the application is
compiled into MSIL. This MSIL is then further compiled into native CPU instructions when the application is
executed for the first time by the CLR. (Actually, only the called functions are compiled the first time they are
invoked.)

1. You write source code in C#.


2. You then compile it using the C# compiler (csc.exe) into an EXE.
3. The C# compiler outputs the MSIL code and a manifest into a read-only part of the EXE that has a standard
PE (Win32-portable executable) header.
4. When the compiler creates the output, it also imports a function named "_CorExeMain" from the .NET
runtime.
5. When the application is executed, the operating system loads the PE, as well as any dependent dynamic-link
libraries (DLLs), such as the one that exports the "_CorExeMain" function (mscoree.dll), just as it does with
any valid PE.
6. However, since the operating system obviously can't execute the MSIL code, the entry point is just a small
stub that jumps to the "_CorExeMain" function in mscoree.dll.
7. The "_CorExeMain" function starts the execution of the MSIL code that was placed in the PE.
8. Since MSIL code cannot be executed directly, because it's not in a machine-executable format, the CLR
compiles the MSIL using the Just-In-Time (JIT) compiler (or JITter) into native CPU instructions as it
processes the MSIL. The JIT compiling occurs only as methods in the program are called. The compiled
executable code is cached on the machine and is recompiled only if there's some change to the source code.

Benefits of .NET technology


.NET technology offers a number of benefits to developers. Some of them are given below:
1. Consistent programming model.
2. Direct support for security
3. Simplified development efforts
4. Easy application development
5. Easy application maintenance
6. Cross-language compatibility
7. Automatic management of resources
8. Cross-platform support

1. Consistent programming model:-


The functionality that the .NET class library provides is available to all .NET languages resulting in a consistent
object-oriented programming model regardless of the programming language the developer uses. So, one can use
this model to create programs for performing different tasks, such as connecting to and retrieving data from
databases, and reading from and writing to files.

2. Direct support for security:-


It uses industry-standard protocols such as TCP/IP, XML, SOAP, and HTTP to facilitates distributed application
communications. This makes distributed computing more secure because .NET developers co-operate with network
security devices instead of working around their security limitations.

3. Simplified development efforts:-


The .NET framework simplifies development by separating the application logic and presentation logic, making it
easier to maintain the code. In web applications, design code and the actual code are written separately eliminating
the need to mix HTML code with ASP code.

4. Easy application development:-


The .NET framework makes it easy to deploy applications. In the most common form, to install an application,
along with the components it requires a directory on the target computer. The .NET framework provides easy
deployment of the application by installing new applications or components that do not have an adverse effect on
the existing applications. In .NET, applications are deployed in the form of assemblies; therefore, registry entries
are not required to store information about components and applications. In addition, problems that used to arise
due to different versions of an assembly are also overcome or eliminated in the .NET framework since assemblies
also store information about different versions of the components used by an application.
5. Easy application maintenance:-
The .NET framework ensures that all the components that the application depends on, are available on the computer
before the application begins to execute. Thus, it becomes easier to maintain the application in .NET framework.

6. Cross-language compatibility:-
Cross-language compatibility means .NET components can interact with each other, irrespective of the languages
that they are written in. An application written in VB.NET can reference a DLL file written in C# or a C#
application can refer to a resource written in VC++ etc. This allows the reusability of code and improves the
efficiency of the development process.

7. Automatic management of resources:-


When you create a .NET application, you do not need to manually free application resources, such as files,
memory, network, and database connections. The CLR automatically tracks the resource usage and saves you from
the task of manual resource management.

8. Cross-platform support:-
Any windows platform that supports CLR can execute the .NET application, i.e., the .NET application enables
interoperability between multiple windows operating system.

Limitations of .NET technology


Following are the limitations of .NET technology:

1. Security is comparatively lesser and many familiar things can reveal as reverse engineering of codes is easy.
2. Newer versions of frameworks are not at all pre-installed in any version of windows.
3. In the older versions of windows, the framework may not be pre-installed. Hence it should be checked first
and if not, you should follow the guidelines in the user manual.
4. Time consumption may be more in some cases due to regularly occurring garbage collection for reclaiming
memory.
5. Limited object-relational (OR) support as it comes only with entity framework.
6. Does not come with multi-platform support from Microsoft, and is not available right after installing visual
studio.
7. Involves a vendor lock-in, and future development solely dependent on Microsoft.
8. Migrating applications to .NET can be expensive.

CIL or MSIL | Microsoft Intermediate Language or Common Intermediate Language


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 “AKSU is given as follows:
using System;

public class Demo {


public static void Main()
{
Console.WriteLine("AKSU");
}
}
The MSIL that is created by the C# compiler for the code provided above is given as follows:
// =============== CLASS MEMBERS DECLARATION ===================

.class public auto ansi beforefieldinit Demo


extends [mscorlib]System.Object
{
.method public hidebysig static void Main() cil managed
{
//
.maxstack 8
IL_0000: nop
IL_0001: ldstr "AKSU"
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: ret
} // end of method Demo::Main

.method public hidebysig specialname rtspecialname


instance void .ctor() cil managed
{
//
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Demo::.ctor

} // end of class Demo

// =============================================================
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 “AKSU” 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.

.Net Assembly
The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may
or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All
the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest.
The designers of .NET have worked a lot on the component (assembly) resolution.

An Assembly is a basic building block of .Net Framework applications. It is basically a compiled code that can be
executed by the CLR. An assembly is a collection of types and resources that are built to work together and form a
logical unit of functionality. An Assembly can be a DLL or exe depending upon the project that we choose.

Assemblies are basically the following two types:

1. Private Assembly
2. Shared Assembly

1. Private Assembly

It is an assembly that is being used by a single application only. Suppose we have a project in which we refer to a
DLL so when we build that project that DLL will be copied to the bin folder of our project. That DLL becomes a
private assembly within our project. Generally, the DLLs that are meant for a specific project are private
assemblies.

2. Shared Assembly

Assemblies that can be used in more than one project are known to be a shared assembly. Shared assemblies are
generally installed in the GAC. Assemblies that are installed in the GAC are made available to all the .Net
applications on that machine.
.NET Framework Class Library (FCL)

The Framework Class Library or FCL provides the system functionality in the .NET Framework as it has various
classes, data types, interfaces, etc. to perform multiple functions and build different types of applications such as
desktop applications, web applications, mobile applications, etc. The Framework Class Library is integrated with
the Common Language Runtime (CLR) of the .NET framework and is used by all the .NET languages such as C#,
F#, Visual Basic .NET, etc.
Categories in the Framework Class Library
The functionality of the Framework Class Library can be broadly divided into three categories i.e utility features
written in .NET, wrappers around the OS functionality and frameworks. These categories are not rigidly defined
and there are many classes that may fit into more than one category.

Details about the Categories in the Framework


Class Library are given as follows:
• Utility Features: The utility features in the
FCL includes various collection classes such as
list, stack, queue, dictionary, etc. and also
classes for more varied manipulations such as
Regex class for regular expressions.
• Wrappers Around OS functionality: Some
of the features in the FCL are wrappers around
the underlying Windows OS functionality.
These include the classes for using the file
system, the classes to handle the network
features, the classes to handle I/O for console
applications, etc.
• Frameworks: There are various frameworks
available in the FCL to develop certain applications. For example, ASP.NET is used to develop web
applications, Windows Presentation Foundation (WPF) is used to render user interfaces in Windows applications
and so on.
Namespaces in the Framework Class Library
Namespaces in the Framework Class Library are a group of related classes and interfaces that can be used by all
the .NET framework languages. Some of the namespaces in the FCL along with their description is given as
follows:
Namespace Description

The Accessibility namespace is a part of the managed wrapper for the COM
Accessibility accessibility interface.

The Microsoft.Activities namespace provides support for Windows Workflow


Microsoft.Activities Foundation applications.

The Microsoft.CSharp namespace has support for compilation and code


Microsoft.CSharp generation for the C# source code.

The Microsoft.JScript namespace has support for compilation and code


Microsoft.Jscript generation for the JScript source code.
Namespace Description

The Microsoft.VisualBasic namespace has support for compilation and code


Microsoft.VisualBasic generation for the VisualBasic source code.

The System namespace has base classes for definition of interfaces, data types,
System events, event handlers, attributes, processing exceptions etc.

The System.Activities namespace handles the creation and working with


System.Activities activities in the Window Workflow Foundation using various classes.

The System.Collections namespace has multiple standard, specialized, and


System.Collections generic collection objects that are defined using various types.

The System.Configuration namespace handles configuration data using various


System.Configuration types. This may include data in machine or application configuration files.

The System.Data namespace accesses and manages data from various sources
System.Data using different classes.

The System.Drawing namespace handles GDI+ basic graphics functionality.


Various child namespaces also handle vector graphics functionality, advanced
System.Drawing imaging functionality, etc.

The System.Globalization namespace handles language, country, calendars


System.Globalization used, format patterns for dates, etc. using various classes.

The System.IO namespaces support IO like data read/write into streams, data
System.IO compression, communicate using named pipes etc. using various types.

The System.Linq namespace supports Language-Integrated Query (LINQ)


System.Linq using various types.

The System.Media namespace handles sound files and accessing the sounds
System.Media provided by the system using various classes.

The System.Net namespace provides an interface for network protocols, cache


policies for web resources, composing and sending e-mail etc. using various
System.Net classes.

The System.Reflection namespace gives a managed view of loaded methods,


System.Reflection types, fields, etc. It can also create and invoke types dynamically.

The System.Security namespace has the .NET security system and permissions.
System.Security Child namespaces provide authentication, crytographic services etc.

The System.Threading namespace allows multithreaded programming using


System.Threading various types.
Namespace Description

XamlGeneratedNames The XamlGeneratedNamespace has compiler-generated types that are not used
pace directly from the code.

Garbage Collection in C# | .NET Framework


Automatic memory management is made possible by Garbage Collection in .NET Framework. When a class
object is created at runtime, certain memory space is allocated to it in the heap memory. However, after all the
actions related to the object are completed in the program, the memory space allocated to it is a waste as it cannot
be used. In this case, garbage collection is very useful as it automatically releases the memory space after it is no
longer required.
Garbage collection will always work on Managed Heap and internally it has an Engine which is known as
the Optimization Engine.
Garbage Collection occurs if at least one of multiple conditions is satisfied. These conditions are given as follows:
• If the system has low physical memory, then garbage collection is
necessary.
• If the memory allocated to various objects in the heap memory
exceeds a pre-set threshold, then garbage collection occurs.
• If the GC.Collect method is called, then garbage collection occurs.
However, this method is only called under unusual situations as
normally garbage collector runs automatically.
Phases in Garbage Collection
There are mainly 3 phases in garbage collection. Details about these are
given as follows:

1. Marking Phase: A list of all the live objects is created during the
marking phase. This is done by following the references from all the
root objects. All of the objects that are not on the list of live objects
are potentially deleted from the heap memory.
2. Relocating Phase: The references of all the objects that were on the list of all the live objects are updated in the
relocating phase so that they point to the new location where the objects will be relocated to in the compacting
phase.
3. Compacting Phase: The heap gets compacted in the compacting phase as the space occupied by the dead
objects is released and the live objects remaining are moved. All the live objects that remain after the garbage
collection are moved towards the older end of the heap memory in their original order.

Metadata in .NET
Metadata is information about the assemblies, modules, and types that constitute .NET programs.
In .NET, metadata is a common mechanism that the .NET runtime, compilers, and tools all can use. Microsoft
.NET uses metadata to describe all types that are used and exposed by the particular .NET assembly.
In this sense, metadata describes an assembly in detail, including descriptions of its identity, the types that it
references, the type that it exports, and the security requirements for execution. Much richer than a type library,
metadata includes descriptions of an assembly and modules, classes, interfaces, methods, properties, fields, events,
global methods, and so forth.
Metadata provides enough information for any runtime, tool, or program to find out literally everything that is
needed for component integration.
Users of metadata in .NET
Following are the users that make intelligent use of metadata in .NET

1) CLR
The CLR uses metadata for verification, security enforcement, memory layout, and execution. The CLR relief
heavily on metadata to support these runtime features.

2) Classloader
A component of the CLR, the class loader uses metadata to find load .NET classes. This is because metadata
records detailed information for a specific class and where the class is located, whether it is in the same assembly,
within or outside of a specific namespace, or in a dependent assembly somewhere on the network.

3) Just-in-time (JIT) compilers


JIT compilers use metadata to compile IL code. .NET JIT compiles IL into native code prior to execution and it
does this using metadata.

4) Tools
Tools use metadata to support integration. Tools such as debuggers, profilers, and object browser can use metadata
to provide richer development support.

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 {

// Namespace (Nested Namespaces)


// Classes
// Interfaces
// Structures
// Delegates

}
Example:
// defining the namespace name1
namespace name1
{
// C1 is the class in the namespace name1
class C1
{
// class code
}
}
Accessing the Members of Namespace
The members of a namespace are accessed by using dot(.) operator. A class in C# is fully known by its respective
namespace.

Syntax:
[namespace_name].[member_name]
Note:
• Two classes with the same name can be created inside 2 different namespaces in a single program.
• Inside a namespace, no two classes can have the same name.
• In C#, the full name of the class starts from its namespace name followed by dot(.) operator and the class
name, which is termed as the fully qualified name of the class.
Example:
// C# program to illustrate the
// use of namespaces

// namespace declaration
namespace first {

// name_1 namespace members


// i.e. class
class Geeks_1
{

// function of class Geeks_1


public static void display()
{
// Here System is the namespace
// under which Console class is defined
System.Console.WriteLine("Hello Geeks!");

}
}

/* Removing comment will give the error


because no two classes can have the
same name under a single namespace

class Geeks_1
{

} */

} // ending of first namespace


// Class declaration
class Geeks_2
{
// Main Method
public static void Main(String []args)
{

// calling the display method of


// class Geeks_1 by using two dot
// operator as one is use to access
// the class of first namespace and
// another is use to access the
// static method of class Geeks_1.
// Termed as fully qualified name
first.Geeks_1.display();

}
}
Output:
Hello Geeks!
In the above example:
• In System.Console.WriteLine()” “System” is a namespace in which we have a class named “Console” whose
method is “WriteLine()“.
• It is not necessary to keep each class in C# within Namespace but we do it to organize our code well.
• Here “.” is the delimiter used to separate the class name from the namespace and function name from the
classname.
The using keyword
It is not actually practical to call the function or class(or you can say members of a namespace) every time by
using its fully qualified name. In the above example, System.Console.WriteLine(“Hello
Geeks!”); and first.Geeks_1.display(); are the fully qualified name. So C# provides a keyword “using” which
help the user to avoid writing fully qualified names again and again. The user just has to mention the namespace
name at the starting of the program and then he can easily avoid the use of fully qualified names.
Syntax:
using [namespace_name][.][sub-namespace_name];
In the above syntax, dot(.) is used to include subnamespace names in the program.

Example:
// predefined namespace name
using System;
// user-defined namespace name
using name1

// namespace having subnamespace


using System.Collections.Generic;
Program:
// C# program to illustrate the
// use of using keyword
// predefined namespace
using System;

// user defined namespace


using first;

// namespace declaration
namespace first {

// name_1 namespace members


// i.e. class
class Geeks_1
{

// function of class Geeks_1


public static void display()
{
// No need to write fully qualified name
// as we have used "using System"
Console.WriteLine("Hello Geeks!");

}
}

} // ending of first namespace

// Class declaration
class Geeks_2
{

// Main Method
public static void Main(String []args)
{

// calling the display method of


// class Geeks_1 by using only one
// dot operator as display is the
// static method of class Geeks_1
Geeks_1.display();

}
}
Output:
Hello Geeks!

What types of applications can we develop using .Net?


When you hear .NET, the first idea that comes to your mind will probably be internet or networked applications.
Although this is absolutely true, there are many more types of applications to create with .NET.

So here is a more or less full list of various types of application that we can develop on .NET.

•ASP.Net Web applications are programs that used to run inside some web server to fulfill the user requests over
the http. ASP.NET Web applications can range from simple Web sites that consist of HTML pages to advanced
enterprise applications that run on local and remote networks. These enterprise applications also provide
components for exchanging data using XML. This type includes dynamic and data driven browser based
applications. (Ex: Hotmail and Google).
•Web services are “web callable” functionality available via industry standards like HTTP, XML and SOAP.
•Windows applications are form based standard Windows desktop applications for common day to day tasks. (Ex:
Microsoft word). Run only under Windows environment. These applications consume the services provided by the
Windows operating system.
•Windows services are long-running executable applications that run on the system as a background process. These
applications do not interfere with the working of the other processes that run on the same computer. Windows
services execute within separate Windows sessions created specifically for each Windows service. These services
do not have a graphic user interface and are ideal for running on the server. Windows services were earlier called
NT services.
•Console applications are light weight programs run inside the command prompt (DOS) window. They are
commonly used for test applications.
•Mobile applications can run on multiple mobile devices, such as Pocket PCs, mobile phones, or personal digital
assistants. These applications provide ubiquitous access to data from mobile devices. The .NET Framework
automatically makes changes to these applications to enable them to run on multiple browsers, depending on the
mobile device.
•Class libraries are components that you create once and reuse a number of times in multiple applications. Class
libraries allow you to define several classes, along with their methods and interfaces, in one file. These libraries
compile to .dll files and facilitate rapid development of new applications because of reusability of code. To access
the functionality of the classes in a class library from your application, you need to include a reference to that
library in your program.
All types of .NET applications use one or more .NET compliant languages for their design and development. The
.NET Framework includes various technologies, such as ASP.NET, VB.NET, VC++.NET, and ADO.NET. You use
ASP.NET to build Web applications and services, VB.NET and VC++.NET to create Windows applications, and
ADO.NET for flexible access to databases.

You might also like