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

Introduction to .

NET Framework SKNSCOEK

Unit-1
Introduction to .NET Framework
...……………………………………………………………………………………………………

The .NET architecture


.NET is tiered, modular, and hierarchal. Each tier of the .NET Framework is a
layer of abstraction. .NET languages are the top tier and the most abstracted
level. The common language runtime is the bottom tier, the least abstracted,
and closest to the native environment. This is important since the common
language runtime works closely with the operating environment to manage
.NET applications. The .NET Framework is partitioned into modules, each with
its own distinct responsibility. Finally, since higher tiers request services only
from the lower tiers, .NET is hierarchal. The architectural layout of the .NET
Framework is illustrated in Figure 1.1.

Figure 1.1 An overview of the .NET architecture.

1
Introduction to .NET Framework SKNSCOEK

.NET Framework is a managed environment. The common language runtime


monitors the execution of .NET applications and provides essential services. It
manages memory, handles exceptions, ensures that applications are well-
behaved, and much more.

Language interoperability is one goal of .NET. .NET languages share a common


runtime (the common language runtime, a common class library), the
Framework Class Library (FCL), a common component model, and common
types. In .NET, the programming language is a lifestyle choice. Except for subtle
differences, C#, VB.NET, or JScript.NET offer a similar experience.

.NET abstracts lower-level services, while retaining most of their flexibility. This
is important to C-based programmers, who shudder at the limitations
presented in Visual Basic 6 and earlier.

Let us examine each tier of the .NET Framework as it relates to a managed


environment, language interoperability, and abstraction of lower-level services.

What is C#?

C# (pronounced as "c-sharp") is an object-oriented general-purpose programming language


created by Microsoft. C# can be used to build windows applications, web applications, web
services, mobile applications, games, and many more. It is a language that even beginners
and students can easily understand. C# has a similar syntax or look-and-feel as other
languages such as C++ and Java. The term Visual C# can be interchangeably used with C#
but Visual C# specifically means C# when used for creating graphical user interfaces (GUI).

Along with the birth of C# is the birth of .NET Framework which is a library of code that you
can reuse when programming (more on .NET Framework on the next lesson). The C#
programming language is the only language specifically designed for the .NET Framework. In
other words, C# can use the full power of the .NET Framework library. It is a very powerful
language that uses object-oriented programming principles which makes programming more
manageable, scalable, and easier to understand and debug. C# offers simpler and easier to
understand syntax compared to other languages.

In order to run a C# application, the .NET framework must be installed first. C# is one of the
languages supported by many .NET technologies such as ASP.NET, WPF, and WCF. C# has its
own Integrated Development Environment which contains useful tools that aid you in coding
with C#. Applications you can write using C# ranges from Windows Applications to Web

2
Introduction to .NET Framework SKNSCOEK

Applications. With the introduction of C# 6.0, new features have been added to this language
that helps you be more productive and do more with less code.

What is .NET Framework?


The .NET Framework ("dot net") is a platform created by Microsoft used for developing
different kinds of applications for the Microsoft Windows platform. The .NET Framework
can also be used for developing web applications, and even mobile applications. Several
versions of the .NET have been released in the past and each iteration adds many features
to the previous version. The latest version of .NET is 4.5.2. The .NET Framework contains
the .NET Framework Class Library (FCL) which is a gigantic library of classes, structures,
enumerations, basic types, and many more which are grouped together into different
assemblies. Although .NET Framework applications are designed for Windows and will only
run on that platform, newer efforts from Microsoft aimed to bring .NET to other platforms
such as Mac and Linux. Microsoft is currently putting an effort to open source .NET
(currently a subset of .NET framework called .NET Core).

Common Language Runtime

(CLR) is the core of .NET which runs .NET applications. It enables the .NET framework to
understand a number of supported languages such as C#, Visual Basic, and C++. This
allows you to code your application in any of the supported .NET languages. The code that
runs under the CLR and .NET is called managed code because the CLR manages different
aspects of your application during runtime.

Common Intermediate Language

During compilation, source codes are compiled into Common Intermediate Language (CIL)
code. We have to convert our source code into CIL because it is the only language that can
be understood by .NET. For example, code in C# and Visual Basic both compile to CIL. That
is why different .NET applications written in different languages can still communicate to

3
Introduction to .NET Framework SKNSCOEK

each other. For example, an application that is written in C# can call the methods of
another assembly that is written in Visual Basic.NET. If you want a language to be .NET-
compatible, you can create a compiler that compiles your code into CIL.

The framework class library

The .NET Framework Class Library (FCL) is a set of managed classes that
provide access to system services. File input/output, sockets, database access,
remoting, and XML are just some of the services available in the FCL.
Importantly, all the .NET languages rely on the same managed classes for the
same services. This is one of the reasons that, once you have learned any .NET
language, you have learned 40 percent of every other managed language. The
same classes, methods, parameters, and types are used for system services
regardless of the language. This is one of the most important contributions of
FCL.

Look at the following code that writes to and then reads from a file. Here is the
C# version of the program.

//C#Program
static public void Main()
{
StreamWriter sw=new StreamWriter("date.txt ",true);
DateTime dt=DateTime.Now;
string datestring=dt.ToShortDateString()+" "+
dt.ToShortTimeString();
sw.WriteLine(datestring);
sw.Close();
StreamReader sr=new StreamReader("date.txt ");
string filetext=sr.ReadToEnd();
sr.Close();
Console.WriteLine(filetext);
}

Just-In-Time

Once your code is compiled to Common Intermediate Language and stored in an assembly
such as .exe or .dll files, the job is transferred to the Just-In-Time (JIT) compiler. The JIT

4
Introduction to .NET Framework SKNSCOEK

compiles the CIL code into native code (the language of computers) only when that part of
code is needed by the program (hence the term "just in time"). The compiled native code is
automatically optimized for the current OS or machine. This is one advantage of using
.NET.

The following summarizes how your C# code is transformed into a machine executable
program.

1. The programmer writes a program in a .NET compatible language such as C#.


2. The C# code is compiled into its CIL code equivalent.
3. The CIL is stored in an assembly such as an .exe or .dll file.
4. When the assembly is executed or called, the JIT compiles the CIL code to native
code that the computer can execute.

Common Type System

The .NET Framework also has a feature called the Common Type System (CTS). This is
the mapping of the data types specific to a language to its equivalent type in the .NET
Framework. Data types are representations of data. For example, whole numbers are
represented by the int data type. With CTS, the int data type in C# and the Integer data
type in Visual Basic are the same because both are mapped to the .NET type System.Int32.

Garbage collection is another feature of the .NET Framework. When resources are no
longer in use, .NET Framework frees up the memory used by an application. The garbage
collector is called whenever it is needed by an application although you can call GC
manually to clean up resources for you.

Installing .NET Framework


To be able to run a .NET application, you must first install it in your computer. Latest
release of Windows 7, 8, 8.1 and 10 operating systems has .NET pre-installed. If your
system doesn't have .NET installed yet, you can download it by clicking the link below:
Microsoft .NET Framework 4.5

5
Introduction to .NET Framework SKNSCOEK

After downloading, run the installer and follow the instructions given by the installation
wizard. You might need to restart the computer after or during installation. (You can skip
this standalone .NET installation for now and wait for Visual Studio installation which will
automatically install .NET for you. We will discuss Visual Studio in the next lesson).

Welcome to Visual Studio

We will now explore the important parts of the visual studio. After Visual Studio starts up,
you will be welcomed by the following screenshot.

Figure 1 - The Visual Studio IDE

The numbered labels will be used to identify the different parts of the IDE.

The Menu Bar

6
Introduction to .NET Framework SKNSCOEK

The Menu Bar (1) is where the different menus for creating, developing, maintaining,
debugging, and executing programs can be found. Clicking a menu will reveal another set of
related menus. Note that the menu bar still has hidden menu items which will only show on
certain conditions. For example, the Project menu item will show if a project is currently
active. Here are some of the description of each menu item.
Menu
Description
Item

Contains commands to create new projects or files, open or save projects, exit or
File
close projects, printing, and many file or project related tasks.

Contains commands to that are related to editing such as selecting, copying,


Edit
pasting, finding, and replacing.

Allows you to open more windows that are initially hidden or add more toolbars
View
items to the toolbar.

Will only show once a project is open. Contains commands related to the projects
Project
you are working on.

Debug Allows you to compile, debug(testing), and run the project.

Only available on certain types of project. Contains command for connecting or


Data
creating different data sources for use in your application.

Only available on certain types of project. Contains commands for arranging the
Format
layout of GUI components while in the Design View.

Tools Contains the different tools, settings, and options for Visual Studio.

Test Allows you to run and debug unit tests.

Window Allows you to adjust the view or layout of the windows inside Visual Studio.

Allows you to view the documentation and help topics, product registration
Help
details, and product version details.

The Toolbars
The Toolbars Section (2) contains different toolbars with commonly used commands which
can also be found in the menu bar. The toolbars serve as a shortcut to commands located in
the menu bar. Each button has an icon that represents its functionality. You can hover on
each button to show a tool tip that describes what its purpose. Some commands are initially
hidden and will only show up on appropriate situations. You can also right-click on any blank
area of the toolbar to add more commands. Alternatively, you can go to View > Toolbars and
check items to show up more toolbars. Some buttons have arrows beside them that when

7
Introduction to .NET Framework SKNSCOEK

clicked, shows more related commands. You can also click the arrows beside each toolbar
that will allow you to add or remove more buttons to the toolbar. The left side of each toolbar
allows you to move it so you can change the arrangement of the toolbars. Right-clicking an
empty area in the toolbars section allows you to select more toolbars to show in the toolbar
section.

The Start Page


You will see some tips, tutorials and news in the Start Page (3) section of the IDE. You can
also create or open projects from here. If you have created some projects, then they will show
up here in the Recent Projects section so you won't have a hard time finding each project. You
can always open the Start Page by going to View > Start Page menu.

There is more to explore in Visual Studio and more parts of the program and features will be
explained in the following lessons.

Introduction to Visual Studio .NET and Sharp Develop IDE

Visual Studio is the all-in-one development environment for developing software using
Microsoft Technologies. If you will be programming in C#, it is recommended to install and
use Visual Studio. There are multiple versions of Visual Studio, both paid and free (we will
be using the free version). Visual Studio is an Integrated Development Environment
(IDE) for building .NET applications and even non-.NET ones. You can create a C#
application just by using a notepad or any text editor to type your codes. You can then use
the C# compiler available when you install .NET. But that can be a tedious process and
errors would be hard to detect.

It is recommended to use an IDE when creating programs. These IDE's are equipped with
great features that help you when developing C# applications. A lot of processes that takes
time to do can be automated by Visual Studio. One of its features is IntelliSense which
guides you as you type your code. Debugging for errors is easier by adding breakpoints to
your code which allows you to pause the execution of code at a certain part and check the
current values of the variables in your program when it is running. Visual Studio can also
detect errors in your program as you type and even try to fix minor errors such as
capitalization. It includes designer tools for creating graphical user interfaces which
generate the long code that you need to manually type if not using Visual Studio. With

8
Introduction to .NET Framework SKNSCOEK

these powerful features, your productivity will increase and development times will
decrease.

Currently, the latest version of Visual Studio is Visual Studio 2015. This version is further
split into different versions. The paid version of Visual Studio will have varying features
depending on the version. The cheapest version is Visual Studio Professional and the most
expensive one is Visual Studio Enterprise. Visual Studio Professional will have most of what
you will need for development. Good news has come when Microsoft decided to open-source
.NET. This follows the introduction of an all-new and free version of Visual Studio, the
Visual Studio Community. Visual Studio Community will be equivalent to Visual Studio
Professional in terms of features although it will be totally free for open-source
development, students, and small teams. This will effectively replace the Visual Studio
Express versions which is also free but has way more limited features than the Professional
version. We will be using Visual Studio Community in our tutorials, but you can also use
the Express or paid versions to follow along.

You might also like