0% found this document useful (0 votes)
14 views7 pages

Unit I

.NET Framework is a comprehensive software framework developed by Microsoft for building applications primarily on Windows, featuring a large class library (FCL) and a runtime environment (CLR) that supports multiple programming languages and interoperability. It includes essential components such as metadata, managed and unmanaged code, and Just-In-Time (JIT) compilation, which optimize application performance and memory management. Visual Studio serves as the integrated development environment for .NET applications, providing various tools and templates for efficient software development.

Uploaded by

aman8122002
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)
14 views7 pages

Unit I

.NET Framework is a comprehensive software framework developed by Microsoft for building applications primarily on Windows, featuring a large class library (FCL) and a runtime environment (CLR) that supports multiple programming languages and interoperability. It includes essential components such as metadata, managed and unmanaged code, and Just-In-Time (JIT) compilation, which optimize application performance and memory management. Visual Studio serves as the integrated development environment for .NET applications, providing various tools and templates for efficient software development.

Uploaded by

aman8122002
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/ 7

UNIT -I Introduction to .

Net Framework
Introduction:
The .NET is a very large framework and sometimes is hard to decide whether to code something or use an existing component of the
framework. Sometimes is faster to code, but when production workload and reliability comes into play, the perspective is different. An
overview of what .NET offers is a fundamental knowledge. It is hard to keep in track because .NET evolves very fast. This article
discusses essentials which is the .NET Framework built from.
.NET Framework (pronounced dot net) is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It
includes a large class library known as Framework Class Library (FCL) and provides language interoperability(each language can use
code written in other languages) across several programming languages. Programs written for .NET Framework execute in
a software environment (as contrasted to hardware environment), known as Common Language Runtime (CLR), an application virtual
machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute
.NET Framework.
FCL provides user interface, data access, database connectivity, cryptography, web application development, numeric alagorithms,
and network communications. Programmers produce software by combining their own source code with .NET Framework and other
libraries. .NET Framework is intended to be used by most new applications created for the Windows platform. Microsoft also
produces an integrated development environment largely for .NET software called Visual Studio.
.NET Framework started out as a proprietary framework, although the company worked to standardize the software stack almost
immediately, even before its first release. Despite the standardization efforts, developers—particularly those in the free and open-
source software communities—expressed their uneasiness with the selected terms and the prospects of any free and open-source
implementation, especially with regard to software patents. Since then, Microsoft has changed .NET development to more closely
follow a contemporary model of a community-developed software project, including issuing an update to its patent that promises to
address the concerns.
The .NET Framework is a new and revolutionary platform created by Microsoft for developing applications.
It is a platform for application developers.
It is a Framework that supports Multiple Language and Cross language integration.
IT has IDE (Integrated Development Environment).
Framework is a set of utilities or can say building blocks of your application system.
.NET Framework provides GUI in a GUI manner.
.NET is a platform independent but with help of Mono Compilation System (MCS). MCS is a middle level interface.
.NET Framework provides interoperability between languages i.e. Common Type System (CTS)
.NET Framework also includes the .NET Common Language Runtime (CLR), which is responsible for maintaining the execution of
all applications developed using the .NET library.
The .NET Framework consists primarily of a gigantic library of code.
Overview
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European
Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).
C# was developed by Anders Hejlsberg and his team during the development of .Net Framework.
C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that
allows use of various high-level languages on different computer platforms and architectures.
The following reasons make C# a widely used professional language −
It is a modern, general-purpose programming language
It is object oriented.
It is component oriented.
It is easy to learn.
It is a structured language.
It produces efficient programs.
It can be compiled on a variety of computer platforms.
It is a part of .Net Framework.

.Net Framework Diagram


Common Language Specification (CLS) / Common Type System (CTS)
As we saw we have many .Net languages but all the languages produce the MSIL as output. This MSIL is common. So the target
types are shared by all the languages. These target type are the types that is defined in the MSIL. And all the languages have to obey
some rules for generating the MSIL like syntax and types. The rules that should be followed by any .Net languages are called CLS or
Common Language Specification. And there are some set of types in the MSIL that should be supported by any language as a
minimum requirement. These set of types are called CTS or Common Type System. There are some types outside the CTS, but these
type are optional may be supported by a language. Each language will have its own boundary like the following diagram.

In the above diagram we could see that all the languages supports the CTS minimally and some extra types. And diagram also shows
all the languages obey the rules defined in the CLS. We achieve the interoperability through this CTS. Since all the .Net languages are
expected to support CTS it is guaranteed that types inside this CTS are fully interoperable.
What is CTS
CTS define all of the basic types that can be used in the .NET Framework and the operations performer on those type.
All this time we have been talking about language interoperability, and .NET Class Framework. None of this is 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. This is achieved through introduction of Common Type System (CTS).

WHAT IS A CLR?
CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that converts a MSIL code into the host machine language
code, which is then executed appropriately. The CLR is the execution engine for .NET Framework applications. It provides a number
of services, including:
 Code management (loading and execution)
 Application memory isolation
 Verification of type safety
 Conversion of IL to native code.
 Access to metadata (enhanced type information)
 Managing memory for managed objects
 Enforcement of code access security
 Exception handling, including cross-language exceptions
 Full form of CLR is Common Language Runtime and it forms the heart of the .NET framework
 Many different languages and platforms provide a runtime, and the .NET Framework is no exception. You will find, however,
that this runtime is quite different from most.
 The Common Language Runtime (CLR) in the .NET Framework manages the execution of the code and provides access to a
variety of services that will make the development process easier.
 The CLR has been developed to be far superior to previous runtimes, such as the VB runtime, by attaining the following:
 _ Cross-language integration
 _ Code access security
 _ Object lifetime management
 _ Debugging and profiling support
 Code that is compiled and targeted to the CLR is known as managed code. Managed code

What is Just-In-Time (JIT) Compiler in .NET


Just-In-Time compiler 0(JIT) is a part of Common Language Runtime (CLR) in .NET which is responsible for managing the
execution of .NET programs regardless of any .NET programming language. A language-specific compiler converts the source code to
the intermediate language. This intermediate language is then converted into the machine code by the Just-In-Time (JIT) compiler.
This machine code is specific to the computer environment that the JIT compiler runs on.
Working of JIT Compiler: The JIT compiler is required to speed up the code execution and provide support for multiple platforms.
Its working is given as follows:
The JIT compiler converts the Microsoft Intermediate Language(MSIL) or Common Intermediate Language(CIL) into the machine
code. This is done before the MSIL or CIL can be executed. The MSIL is converted into machine code on a requirement basis i.e. the
JIT compiler compiles the MSIL or CIL as required rather than the whole of it. The compiled MSIL or CIL is stored so that it is
available for subsequent calls if required.
Types of Just-In-Time Compiler: There are 3 types of JIT compilers which are as follows:
Pre-JIT Compiler: All the source code is compiled into the machine code at the same time in a single compilation cycle using the
Pre-JIT Compiler. This compilation process is performed at application deployment time. And this compiler is always implemented in
the Ngen.exe (Native Image Generator).

Normal JIT Compiler: The source code methods that are required at run-time are compiled into machine code the first time they are
called by the Normal JIT Compiler. After that, they are stored in the cache and used whenever they are called again.

Econo JIT Compiler: The source code methods that are required at run-time are compiled into machine code by the Econo JIT
Compiler. After these methods are not required anymore, they are removed. This JIT compiler is obsolete starting from dotnet 2.0
Advantages of JIT Compiler:
The JIT compiler requires less memory usage as only the methods that are required at run-time are compiled into machine code by the
JIT Compiler.
Page faults are reduced by using the JIT compiler as the methods required together are most probably in the same memory page.
Code optimization based on statistical analysis can be performed by the JIT compiler while the code is running.

Disadvantages of JIT compiler:


The JIT compiler requires more startup time while the application is executed initially.
The cache memory is heavily used by the JIT compiler to store the source code methods that are required at run-time.

Introduction to Metadata in C#
C# in metadata is defined as the binary information which is describing our program and this information is stored either in common
language runtime portable executable file or in memory. If you compile the code from portable executable file then metadata is
inserted in one more area portion of the file and all this code will now be converted into MSIL format (Microsoft Intermediate
Language) then code moved into another partition portion of the file. All data types and data members that is defined and referenced
in the assembly is put within the metadata. While we are executing the C# code at the runtime, it loads the metadata from the memory.
The main purpose of the C# metadata is to know the information about the class, data members, inheritance, and data types etc. of the
class. Metadata in the file consists of table and heap data structures.
Uses of Metadata
Given below are the uses of Metadata:
It provides description about assembly data types like name, visibility, base class and interfaces etc.
It provides data members like methods, fields, properties, events and nested types.
It also provides additional description of the elements that modify types and members.
It have identity like name, version, public key etc.
It is a key to simple programming model and it will eliminate the necessity for IDL (Interface Definition Language) files, header files.
Difference between managed and unmanaged code
What is Managed Code -

Managed code is the code that is written to target the services of the managed runtime execution environment such as Common
Language Runtime in .Net Technology.
The Managed Code running under a Common Language Runtime cannot be accessed outside the runtime environment as well as
cannot call directly from outside the runtime environment. It refers to a contract of cooperation between natively executing code and
the runtime. It offers services like garbage collection, run-time type checking, reference checking etc. By using managed code you can
avoid many typical programming mistakes that lead to security holes and unstable applications, also, many unproductive programming
tasks are automatically taken care of, such as type safety checking, memory management, destruction of unused Objects etc.

What is Unmanaged Code-


Unmanaged code compiles straight to machine code and directly executed by the Operating System. The generated code runs natively
on the host processor and the processor directly executes the code generated by the compiler. It is always compiled to target a specific
architecture and will only run on the intended platform. So, if you want to run the same code on different architecture then you will
have to recompile the code using that particular architecture.
Unmanaged executable files are basically a binary image, x86 code, directly loaded into memory. This approach typically results in
fastest code execution, but diagnosing and recovery from errors might difficult and time consuming in most cases. The memory
allocation, type safety, security, etc needs to be taken care of by the programmer and this will lead unmanaged code prone to memory
leaks like buffer overruns, pointer overrides etc.
All code compiled by traditional C/C++ compilers are Unmanaged Code. COM components, ActiveX interfaces, and Win32 API
functions are examples of unmanaged code. Managed code is code written in many high-level programming languages that are
available for use with the Microsoft .NET Framework, including VB.NET, C#, J#, JScript.NET etc. Since Visual C++ can be
compiled to either managed or unmanaged code it is possible to mix the two in the same application.

Visual Studio .NET IDE (Integrated Development Environment)


IDE- Integrated Development Environment for all .NET based applications which comes with rich features. VS .NET IDE provides
many options and is packed with many features that simplify application development by handling the complexities. Visual Studio
.NET IDE is an enhancement to all previous IDE’s by Microsoft.
New Project Dialogue Box
The New Project dialogue box like the one in the image below is used to create a new project specifying it's type allowing us to name
the project and also specify it's location on the disk where it is saved. The default location on the hard disk where all the projects are
saved is.
Windows Application
This template allows to create standard windows based applications.

Class Library
Class libraries are those that provide functionality similar to Active X and DLL by creating classes that access other applications.
Windows Control Library
This allows to create our own windows controls. Also called as User Controls, where you group some controls, add it to the toolbox
and make it available to other projects.

ASP .NET Web Application


This allows to create web-based applications using IIS. We can create web pages, rich web applications and web services.
ASP .NET Web Service .Allows to create XML Web Services.

Web Control Library


Allows to create User-defined controls for the Web. Similar to user defined windows controls but these are used for Web.
Console Application: A new kind of application in Visual Studio .NET. They are command line based applications.

Windows Service
These run continuously regardless of the user interaction. They are designed for special purpose and once written, will keep running
and come to an end only when the system is shut down.This template is to develop other kinds of applications like enterprise
applications,database applications

Solution Explorer Window


The Solution Explorer window gives an overview of the solution we are working with and lists all the files in the project.

Server Explorer Window


The Server Explorer window is a great tool that provides "drag and drop" feature and helps us work with databases in an easy
graphical environment. For example, if we drag and drop a database table onto a form, VB .NET automatically creates connection and
command objects that are needed to access that table. The image below displays Server Explorer window.

Code Designer Window


Code Designers like the image below allows us to edit and write code. This is the window that opens when we double-click on a form
or any control. This is the place where we write all the code for the application. Notice the two drop-down list boxes at the top of the
code window in the image below. The left box allows us to select the object's code we are working with and the right box allows us to
select the part of code that we want to work. Also notice the "+" and "-" boxes in the code designer. You can use those boxes to
display code Visual Basic .NET already created, like, Windows Forms Designer generated code, etc.

Properties Window
The properties window allows us to set properties for various objects at design time. For example, if you want to change the font, font
size, backcolor, name, text that appears on a button, textbox etc, you can do that in this window. Below is the image of properties
window. You can view the properties window by selecting
View->Properties Window from the main menu or by pressing F4 on the keyboard.

Command Window
The command window in the image below is a useful window. Using this window we can add new item to the project, add new
project and so on. You can view the command window by selecting
View->Other Windows->Command Window from the main menu. The command window in the image displays all possible
commands with File.

Task List Window


The task list window displays all the tasks that VB .NET assumes we still have to finish. You can view the task list window by
selecting View->Show tasks->All or View->Other Windows->Task List from the main menu. The image below shows that. As you
can see from the image, the task list displayed "TextBox1 not declared", "RichTextBox1 not declared". The reason for that message is,
there were no controls on the form and attempts where made to write code for a textbox and a rich textbox. Task list also displays
syntax errors and other errors you normally encounter during coding

Class View Window


The class view window like the image below is the window that presents solutions and projects in terms of the classes they contain
and the members of these classes. Using the class view window also helps us to find a member of a class that we want to work with.
As you can notice from the image, the class view window displayed all the methods and events for the controls which were available
on the form.

Output Window
The output window as you can see in the image below displays the results of building and running applications.
Object Explorer Window
The object explorer window allows us to view all the members of an object at once. It lists all the objects in our code and gives us
access to them. The image below displays an object explorer window. You can view the object explorer window by selecting View-
>Other Windows-> Object Browser from the main menu.
Toolbox Window
The toolbox window is the window that gives us access to all controls, components, etc. As you can see from the image below, the
toolbox uses tabs to divide it's contents into categories (Data, Components, Windows Forms and General). The Data tab displays tools
for creating datasets and making data connections, the Windows Forms tab displays tools for adding controls to forms, the General tab
is left empty by default, the Clipboard Ring tab displays recent items stored in the clipboard and allows us to select from them
Compilation and Execution Process in C#
C# is a general-purpose, strongly typed, lexically scoped, functional, object-oriented, and component-oriented programming language.
In this article, we are going to learn how C# code gets compiled and executed.
Step-by-step process of C# code compilation

Step 1: Write a C# code.

Step 2: Compile the code using a C# compiler.

Step 3: Now compiler checks if the code contains an error or not. If no error is found then the compiler move to the next step. Or if
the compiler found errors, then it will immediately tell the developer that an error is found in the given line, so that the developer can
correct them. After correcting the error when you again run the code the compiler again check for the errors, if no error found then it
will move to the next step or if an error is found then the compiler gives a message to the developer. In C# there are two types of
errors:
Compiler error
Errors that occur when the developer violates the rules of writing syntax are known as Compile-Time errors. This compiler error
indicates something that must be fixed before the code can be compiled. All these errors are generally detected by the compiler and
thus are known as compile-time errors. For example, missing semicolon, missing parenthesis, etc.
Runtime error
Errors that occur during program execution(run-time) after successful compilation is called run-time errors. One of the most common
run-time errors is division by zero also known as Division error. These types of errors are hard to find as the compiler doesn’t point to
the line at which the error occurs.

Step 4: Languages such as Java or C# are not directly converted or compiled into machine-level language or machine instructions.
These languages need to be converted to an intermediate code first, which is a partially half compiled code. For C#, the source code is
converted to an intermediate code which is known as Common Intermediate Language (CIL) or Intermediate Language Code
(ILC or IL code). This CIL or IL Code can run on any operating system because C# is a Platform Independent Language.

Step 5: After converting the C# source code to Common Intermediate Language (CIL) or Intermediate Language Code (ILC or IL
code, the intermediate code needs to be converted to machine understandable code. C# uses the .NET Framework and as part of this
.NET Framework, the Virtual Machine component manages the execution of programs written in any language that uses the . NET
Framework. This virtual machine component is known as Common Language Runtime (CLR) which translates the CIL or IL code
to native code or machine understandable code or machine instructions. This process is called the Just-In-Time (JIT)
Compilation or Dynamic Compilation which is the way of compiling code during the execution of a program at run time only.

Step 6: Once the C# programs are compiled, they’re physically packaged into Assemblies. An assembly is a file that contains one or
more namespaces and classes. As the number of classes and namespaces in program grows, it is physically separated by related
namespaces into separate assemblies. Assemblies typically have the file extension .exe or .dll, depending on whether they implement
applications or libraries respectively, where EXE stands for Executable and DLL stands for Dynamic Link Library. An EXE
(Executable) file represents a program that can be executed and a DLL (Dynamic Link Library) file includes code (Eg: Library) that
can be reused across different programs.

Step 7: Now, the C# compiler returns the output of the given c# code.

Compilation process of C# code

C# Namespaces
Namespaces in C# are used to organize too many classes so that it can be easy to handle the application.
In a simple C# program, we use System.Console where System is the namespace and Console is the class. To access the class of a
namespace, we need to use namespacename.classname. We can use using keyword so that we don't have to use complete name all the
time.
In C#, global namespace is the root namespace. The global::System will always refer to the namespace "System" of .Net Framework.

C# namespace example
Let's see a simple example of namespace which contains one class "Program".
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Namespace!");
}
}
}
Output:
Hello Namespace!

C# namespace example:
Let's see another 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:
Hello First Namespace
Hello Second Namespace

You might also like