Chapter 1
Introduction to .Net Framework
• .NET is a software framework that is designed and developed by
Microsoft. The first version of the .Net framework was 1.0 which
came in the year 2002. In easy words, it is a virtual machine for
compiling and executing programs written in different languages
like C#, VB.Net, etc.
• It is used to develop Form-based applications, Web-based
applications, and Web services. There is a variety of programming
languages available on the .Net platform, VB.Net and C# being
the most common ones. It is used to build applications for
Windows, phones, web, etc. It provides a lot of functionalities
and also supports industry standards.
• .NET Framework supports more than 60 programming languages
of which 11 programming languages are designed and developed
by Microsoft. The remaining Non-Microsoft Languages are
supported by .NET Framework but not designed and developed
by Microsoft.
What is Framework?
● Framework is collection of reusable classes which represent
software code and design that can be recycled for various
application domains.
● Framework is an essential component of windows operating
system, which helps in creating applications by integrating
different programming languages such as c#, VB, J#, & visual C++.
● A framework can be a collection of libraries and technologies
consist of many reusable classes and line of code.
● .Net framework is a way that helps one to build software
economically.
● .Net framework provides a bridge to make sure the
interoperability between applications which are created using
various languages such as C#, Visual Basic.
Benefits of .Net Framework
1. Consistent programming model: User can able to create programs
for performing different tasks such as database applications as
well as reading and writing in files.
2. Cross-platform support: .Net applications enables interoperability
between multiple windows operating system.
3. Language Interoperability: Code written in different languages
interact with each other, it leads to improves efficiency and
reusability of code.
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 any one .NET language, you can write code in any
.NET language.
Objectives of .Net framework
1. .Net introduced a unified programing Environment: All .Net
enabled languages compiles to “Microsoft intermediate
language” before being assembled into platform-specific machine
code.
2. .Net committed developers to object oriented technologies:
.Net implements object oriented programming paradigm;
everything in .Net is contained in an object.
3. .Net simplified windows programming: With .Net, APIs are
replaced with hierarchy of object providing access to many
commonly needed windows features.
4. .Net provides Security: By using .Net one can limit malicious
programs from doing their damage.
5. .Net enhanced web-based development: Until .Net many
web-based development was done using scripting languages, but
.Net enables the power of compiled, desktop development to the
internet.
ARCHITECTURE OF .NET
FRAMEWORK
Operating
OperatingSystem
System
.Net platform composed of different components likes .Net compatible
languages, Common Languages Specification (CLS), Common Type System
(CTS), .Net Framework Class Library (FCL), common Language Runtime (CLR).
1. .Net Compatible Languages:
.Net has come up with various programming languages which help to
integrate the application designed in different technologies. It
intended to develop the application in different languages and
integrates them together. Different compatible languages such as
VB.NET, C#, Jscript.NET, Visual C++.NET are available.
1. Common language Specification(CLS):
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.
3. .NET Framework Class Library (FCL):
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.
4. common language runtime (CLR):
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.
5. Common Type System (CLT):
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 common type system supports the following types:
• The common type system supports two general categories of types:
1. Value types
2. Reference types
1. Value types
• A data type is a value type, if it holds the data within its own memory
allocation.
• It contains:
– All numeric data types
– Boolean, Char, Date
– All structures (even if their members are reference type)
– Enumerations, since their underlying type is always Byte, Short, Integer
or Long.
2. Reference types
• A reference type contains a pointer to another memory location that holds
the data
– String
– All arrays even if their elements are value types
– Class types such as Form
– Delegates
● First, the developer has to write the code using any dot net supported
programming languages such as C#, VB, J#, etc.
● hen the respective language compiler will compile the program code and
generate something called Microsoft Intermediate language (MSIL) or
Intermediate language (IL) code.
● For example, if the programming language is C#, then the compiler is CSC and
if the programming language is VB, then the compiler will be VBC.
● This Intermediate Language (IL) code is half compiled code i.e. partially
compiled code and cannot be executed directly by the Operating System.
● To execute this Microsoft Intermediate language (MSIL) or Intermediate
language (IL) code on your machine
● the .NET Framework provides something called Common Language Runtime
(CLR) which takes the responsibility to execute your Microsoft Intermediate
language (MSIL) or Intermediate language (IL) Code.
● The CLR takes the IL (Intermediate Language) code and gives it to something
called JIT (Just-in-Time) Compiler.
● The JIT compiler reads each and every line of the IL code and converts it to
machine-specific instructions (i.e. into binary format) which can be executed
by the underlying Operating System.
Base Class Library Support - It is a class library that provides support of
classes to the .NET application.
Thread Support - It manages the parallel execution of the
multi-threaded application.
COM Marshaler - It provides communication between the COM objects
and the application.
Type Checker - It checks types used in the application and verifies that
they match to the standards provided by the CLR.
Code Manager - It manages code at execution run-time.
Garbage Collector - It releases the unused memory and allocates it to a
new application.
Exception Handler - It handles the exception at runtime to avoid
application failure.
ClassLoader - It is used to load all classes at run time.
Just-In-Time
VB.NET/C#.NET Code/.Net Languages
Compiler:
Microsoft Intermediate Languages
(MSIL)
Just In Time (JIT)
Native Code
Operating System
JIT Compiler
● Compiled program in .Net is code called as Microsoft Intermediate
Language (MSIL), which is low level set of instruction understood
by CLR
● This MSIL is not an executable file hence it is necessary to turned
MSIL into an executable code called as Native code or machine
code using JIT(Just In-Time) compiler.
● JIT compiler converts MSIL into native code that it can execute on
the target Operating System.
● This native code understands by operating system and further
executes by it.
● The full MSIL code was not translate into native code, JIT compiler
converts MSIL code into native code on demand basis as each part
of the program is needed.
● JIT compiler dynamically compiles that is optimized for the target
machine.
NOTE:
● User can implement code in any .NET Specific language.
● The code is compiled and generates MSIL code called an Assembly.
● JIT convert MISL into native code also called as machine code
which is a machine understandable code, it is then executed
Base Class Library (BCL)-Core Set
• BCL is smaller library which contains the most
essential features that a program just could not
do without.
• BCL includes only those classes that are an
absolute must for supporting applications on the
framework.
• BCL provides the most foundational types and
utility foundational type and utility functionality
which id base of all other.
• BCL aims to provide general implementation
without bias of any workload.
Advantages of .NET Framework
• Object – Oriented Programming – both the .NET framework and C# are
entirely based on object oriented principles right from the start.
• Good Design – a base class library which is designed from the ground up in
a highly intuitive way.
• Language Independence – with .NET all of the languages Visual Basic .NET,
C#, J# and managed C++ compile to a common Intermediate language.
This means that languages are interoperable in a way that has not been
before.
• Code Sharing - .NET has completely revamped the way that code is shared
between applications, introducing the concept of the assembly, which
replaces the traditional DLL.
• Improved security – each assembly can also contain built – in security
information that can indicate precisely who or what category of user or
process is allowed to call which methods on which classes.
Integrated Development Environment (IDE)
• New Project
• Solution Explorer
• Toolbox
• Editors and Designers
• Properties Window
Event Driven Programming
• Events are basically a user action like key press, clicks, mouse
movements etc.
• Applications need to respond to events when they occur.
• Eg – clicking a button or entering text in text box.
• An event is an action that calls a function or may cause
another event.
• Event handlers are functions that tell how to respond to an
event.
• VB .NET is an event – driven language.
• There are mainly two types of events −
• Mouse events
• E.g - MouseClick,MouseDrag etc.
• Keyboard events
• E.g - KeyDown, KeyUp etc.
User and Program Interface
• The .NET framework provides the following tools for
managing user and application interfaces:
• Windows forms
• Web Forms
• Console Applications
• Web Services
Window Forms
• Windows forms (also called Win Forms) are 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.
• With Win Forms we can make a single user interface, and use it in
VC++, VB, 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.
• In all, Web forms are used to create web
applications.
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.
Web Services
• Web services 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.
• Web Services provides tools for developing web app
applications.
Steps for Installing & Setting Up Visual Studio 2019
Step 1: Download the Visual Studio Community Version
Step 2: Run the .exe file and follow the instructions to install Visual Studio
Community Version on the system.
Step 3: Select ASP.NET and web development from the options and click to install in
bottom right corner as shown below. We can also select .NET desktop development option
for windows forms and console applications etc. Here we are selecting both the options.
We can also modify it after installation.
Step 4: Click on Launch button, and then it shows the below image in your screen that
represents Visual Studio has been successfully launched in your machine.
Step 5: And then it shows a below screen to select the Visual Studio theme. By default, it takes
Blue theme, and if you want to change, you can easily change the Visual Studio theme by
clicking on other themes.
Step 6: After selecting the Theme, click on Start Visual Studio and then it shows a below
image in your system screen for creating a new project.
Step 7: After click on Create a new project, it shows the below screen to choose
what type of application you are going to build in Visual studio. In this you can
select the Console based application or Window Form Based application, as shown
in below image. Here we chose the Console based application, and then click on
the Next button.
Step 8: When you click the Next button, it shows the below image to define the project
name, and also reminds if you want to place the solution and project in the same directory.
Step 9: And finally, your new project will be successfully created.
Example:
Imports System 'System is a Namespace
Module Hello_Program
Sub Main()
Console.WriteLine("Hello, Welcome to the world of VB.NET")
Console.WriteLine("Press any key to continue...")
Console.ReadKey()
End Sub
End Module
Let's compile and run the above program by pressing the F5 key, we get the following
output.