0% found this document useful (0 votes)
19 views

C# - .NET FRAMEWORK

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)
19 views

C# - .NET FRAMEWORK

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

Programming in C#

Unit – I Introduction: architecture and components of .NET


framework 4.5, managed code, intermediate language, meta data
and JIT compiler, common language runtime, automatic memory
management, private and shared assemblies, exploring Visual
Studio .NET IDE.

MICROSOFT NET FRAMEWORK

-​ . Net framework is a technology or a programming infrastructure


used for building and deployment of applications and services that
use .Net technologies like XLM web-b

1.​ The 1st version of .net framework was released in 2000 by the tag
name of .net framework 1.0.
-​ The version was introduced with IDE(Integrated development
environment (visual studio.net)).
-​ The very 1st version of net framework included various features like
introduction of common lang runtime (CLR), DLL class libraries and
provisioning of object oriented web applns development.
2.​ After introduction .net framework version 1.1 & 2.0 adding
numerous features, the development succeeded in launching .net
framework version 3.0.
-​ This included windows presentation foundation(WPF) windows
communication foundation(WCF) & windows workflow
foundation(WF).
-​ MS announced the .Net framework version 3.5 to synchronize the
use of windows 7, XP & server 2003
3.​ MS announced .NET framework version 4.0 in 2010.
-​ The version introduced CLR 4.0,( managed extensibility
framework(MEF)-is a lib to create light weight and extensible
applications) & dynamic language runtime(DLR).
-​ This version included visual studio 2010
4.​ The .Net version 4.5& 4.5.1 included some enhanced features in
additions to CLR 4.0, A synchronization support, windows store
applications, accessibility feature and some common feature
enhancement to WPF, WCF, WF and ASP.NET .
-​ The .NET framework ver 4.5 and 4.5.1 also introduced visual studio
2012 and 2013.
5.​ Afterwards 4.5.2, 4.6(2016), 4.6.1, 4.6.2& 4.7(2017) were also
introduced.

❖​ARCHITECTURE OF THE .NET FRAMEWORK 4.5


-​ The .net framework 4.5 helps in developing portable scalable and
robust applns.
-​ The appln developed in .net framework 4.5 can be executed in
distributed environment.
-​ .net framework is a platform that provides tools and technologies
to develop . NET FRAMEWORK 4.5
ARCHITECTURE windows, web and enterprise applns.
-​ The architecture of .net framework 4.5 mainly consist of the
components of .net framework 3.5 and 4.0.
CTS(common type sys)

1.​ Meta data &assemblies


2.​ .net framework class library (FCL)
3.​ BCL
4.​ Windows forms
5.​ ASP .net &ASP.net asynchronous JAVA SCRIPT &XML(AJAX)
6.​ Active data objects .net (ADO.NET)
7.​ WF
8.​ WPF
9.​ WCF
10.​ Windows card space(WCS)
11.​ LINQ(lang integrated query)
1.​ CLR: The main part of .net framework, which develop the base of
the architecture is CLR.
-​ It acts as a bridge that is used to handle code at execution.
-​ It is the core part of .net framework & is responsible for memory
mgmt, exception handling, debugging, security, thread mgmt, code
execution etc .
-​ CLR also supports versioning to any lang that it interact with
-​ This implies that CLR can host a variety of lang by ensuring
interoperability b/w the codes.
-​ CLR provides runtime environment to run the code. The runtime
manages the execution of the code
-​ ∴ The code that work on CLR is called managed code.
-​ It automatically releases the objs when they are no longer in use
(resolves issues of memory leaks & invalid memory reference)
-​ The runtime imposes code access security (CAS)that enforces
security policies by preventing unauthorized access to protected
resources & options .
-​ The runtime accelerates the productivity by allowing us to write
applns in any lang .
❖​Managed code: is the code that is executed directly by CLR The
applns that are created using managed code automatically have
CLR services, such as type checking security &automatic garbage
collection.​
These services help in providing platform & lang independence
to managed code applns .The CLR complies the applns to
Intermediate lang (IL) or Microsoft IL (MSIL) , but not the
machine code .
This IL along with the meta data (describes attributes, classes
&method of the code) reside in an assemble.
o​ The process of executing managed code is ,
1.​ Selecting a lang complier
2.​ Compiling the code to IL
3.​ Compiling IL to native code
4.​ Executing the code
-​ When u compile the code, the complier converts the source into IT,
which is CPU-Independent.
-​ Before the execution of the code, IT must be converted into
CPU-specific code by JIT-complier.
-​ When u complier source code into IT, the required meta data is
generated.
-​ The meta data contains the definition of types, member signature,
the members in the code and other details that the code uses at
the time of execution.

1.​ Unmanaged code:


-​ it directly complies to the machine code & runs on the machine
where it has been complied unmanaged code, does not have
services, such as security or memory mgmt, which are provided by
runtime.

-​
-​
-​ The .Net framework 4.5 provides components, such as CLR,
BCL, entity framework, windows forms as well as tools to
develop an appln easily.

❖​COMPONENTS OF .NET FRAMEWORK 4.5


-​ The .net framework 4.5 provides all the necessary components
to develop & run .net based applns.
-​ The components are
12.​ CLR
3. Memory mgmt:(most imp service)
-​ The CLR uses the garbage collector to manage the allocation and
release of memory for any applns.
-​ This is beneficial for developer as CLR reduces the burden of
writing code to manage memory.
-​ Automatic memory mgmt removes common problems such as
memory leaks and illegal access.
2.​ CTS:
-​ Specifies certain guidelines for declaring, using and managing type
at run time.
-​ It is an integral part of runtime supporting cross-lang
communication.
o​ The function performed by CTS are :
1.​helps in cross-lang communication, type safety, and high
performance execution of code.
2.​Supports object oriented model for implementing of difference
programming language.
3.​Specifies guidelines for different languages to follow.
4.​Supports primitive data types(Boolean, byte, char, int32....)
-​ The CTS can be classified in to 2 types
1)Value type 2) Reference type
-​ CTS specifies no particular syntax or keywords but instead defines
common set of types that can be used with many different lang
syntax
-​ It defines core semantics but not syntax
-​ Each lang has its own syntax, but if that lang is built on CLR, it will
use atleast some of the types defined by CTS.
(TYPE- set of rules for interpreting the value stored in some
memory location such as value of a variable)
-​ In the managed code, values can have their memory allocated
either on stack managed by CLR or on CLR managed heap.
-​ variables allocated on stack are created when a method is called or
when a running method creates them.
-​ The garbage collector manages the memory allocated to these
types by releasing the memory space of variables when they are
no longer in use.
-​ Variables declared as value type have their own copy of data,
therefore any operator on one variable does not effect another
variable.
-​ Variables that are declared as reference type always point to same
object, any operator on one variable affects the same instance
referred to by another variable.
-​ The base class of all types is System.Object class

Hierarchy of different data types


❖​META DATA & ASSEMBLIES

A meta data is binary information that describes a program


stored in a CLR portable executable(PE) file or memory .

-​ The meta data describes every type & memory.


-​ When the code is in the run mode the CLR loads the meta data
into the memory & finds information about the code’s classes &
memory.
-​ A meta data describes information about the code in langs-neutral
manner.

The meta data contains the following:


1.​ Assemble information, which includes the metadata identity that
can be name; variable, culture, public key, the type of assemblies,
other referenced assemblies & security permissions.
2.​ Information about type such as name, visibility; base class,
interfaces used & memory (methods, fields, properties, events
etc).
3.​ Attribute information that modifies the types & memory of a class.
-​ After providing this information, CLR is able to create objects,
access data & call memory functions.
-​ A module’s meta data contains everything that needed to interact
with another module.
-​ During the compile time, the meta data is created with MSIL &
stored in a file called a manifest.
-​ Both meta data & MSIL together wrapped in a portable executable
file (PE).
-​ During runtime of program, JIT compiler uses metadata & converts
MSIL into native code.
-​ When code is executed the runtime loads metadata into memory
&reference it to discover info about your code’s classes, members,
inheritance& so on

ASSEMBLIES: Assemblies are packaged into units containing


programming and libraries.
-​ An contains a self describing binary file that can be either
DLL(dynamic link library)& .exe(executable)
-​ It also contains collection of types such as classes, interface,
structures.
-​ A single assembly can contain multiple code files or a single code
file can have more than one assembly.
-​ An assembly contains the code that the CLR executes.
-​ Assemblies can be 2 types: 1. Static , 2. Dynamic
1.​ Static assemblies: include interfaces, classes &resources. These
assemblies are stored in the PE files on a disk.
2.​ Dynamic assemblies: run directly from the memory without being
saved to a disk before execution.
1.​ Assembly content: an assembly is a logical unit.
- That consist of 4 elements 1)the manifest, 2)Type metadata
3)IL code 4)set of resources.
- all these elements can be grouped in a single files\multiple files.

2. Assembly manifest : every assembly contains data that describes


how elements are related to each other with in the assembly.
▪​ The manifest also known as assembly manifest, contains the
assembly meta data needed for providing the assemblies version
requirements and security identity.
▪​ The manifest can be stored either in a PE file with IL code or in a
stand alone. PE file that contains only manifest info.
▪​ The info store in assembly manifest – assembly name, version,
number, culture, list of file in assembly, type reference info etc.
3.​Global assembly cache(GAC) : is the central place for registering
assemblies, so that different applns can use it afterwards.
Assemblies must be made sharable by registering them in GAC,
only when needed, otherwise they must be kept private
4.​Strong name assembly: a strong name contains the assemblies
identity. i.e., the info about the assembly’s name, version no,
culture, public key and digital sign.
▪​ Using private key the assembly file containing the manifest
generate a strong name.
▪​ Strong name to an assembly can be provided by using MS Visual
Studio.NET & other development tools. By providing strong name
to an assembly ensures that an assembly is Globally unique,
facilitates integrity check etc.
❖​Private and shared assemblies: when a single appln uses an
assembly, then it is called private assembly.
o​ If u have created a DLL assembly containing info about yours
business logic, then the DLL can be used by yours client appln
only.
o​ Therefore to run the appln, the DLL must be included in same
folder in which client appln has been installed.
o​ Shared assemblies: are those assemblies that are placed in GAC,
so that they can be used by multiple appln.

6​ side by side execution of assemblies: the process of executing


multiple versions of an applns or an assembly is known as side by
side execution.
❖​JIT COMPILATION
1.​ The lang complier complies the source code into MSIL code which
consists of CPU-independent code &instances which is platform
independent.
2.​ MSIL code can be complied into CPU specific instructions before
execution, for which CLR requests meta data
3.​ The JIT complier, which is an integral part of CLR complies the
MSIL code into native code.

JIT Execution process


❖​AUTOMATIC MEMORY MANAGEMENT
-​ Automatic memory mgmt means there is no need to write code to
allocate memory when objects are created or to release memory
when objects are not required by the applns
-​ Automatic memory mgmt involves the following tasks;
1.​ Allocating memory: when a process is initialized, the runtime
reserves a contiguous add space without allocating any storage
space for it.
♦​ This reserved add space is called managed heap.
♦​ The managed heap keeps a pointer at the location, where the next
object will be located.
♦​ When an appln uses the new operator to create an object, the new
operator checks whether the memory required by the object is
available on the heap.
♦​ When the next obj is created , the garbage collector allocates
memory to the obj on the managed heap takes less time than
allocating unmanaged memory.
♦​ In unmanaged memory, the pointers to memory are maintained in
linked list data structures
♦​ ∴Allocating memory requests navigation through linked list.
♦​ Accessing obj’s in managed memory is faster than obj’s in
unmanaged memory, because in managed memory allocation, obj’s
are created contiguously.
2.​ Releasing memory: The garbage collector(GC), periodically
releases memory from the obj’s that are no longer required by the
applns.
♦​ Every appln has a set of roots. These roots point to the storage
location, on the managed heap.
♦​ Each root either refers to an obj on the managed heap or is set to
null.
♦​ An applns root consists of global & static obj pointers, local
variables and reference obj parameters on a thread stack.
♦​ The complier & runtime maintain the list of the appln roots.
♦​ GC(garbage collector), uses this list to create a graph of obj’s on
the managed heap that are reachable from the root list.
♦​ When GC starts running, it consider all the obj’s on the managed
heap as garbage.
♦​ The GC considers all unreachable obj’s on the managed heap as
garbage.
♦​ The GC performs a collection process to free the memory occupied
by garbage obj’s.

4 .NET FCL(framework class library) : .net framework consists of


classes, interface and value types that helps in speeding up the
applns development process & provide access to sys functionality.
o​ To facilitate interoperability b/w langs, .NET framework should be
CLS-complaint so that the code developed in a PL can be used
from another PL can be used from another PL whose complier
conforms to CLS.
o​ The FCL is a huge lib of reusable types meant to be used by
managed codes.
5.​BCL(base class lib):

-​ Is lib that contains some common set of functionalities , such as


reading form & writing in files, designing graphics& interacting with
databases
-​ For all .net framework langs MS has upgraded BCL with every
release of .net framework.

6.​WINDOWS FORM :

-​ Is a graphical representation of any window displayed in an appln.


-​ U can create an appln using windows forms in any CLR supported
lang.
-​ Windows forms can be used either to accept i/p or display info to
user.
-​ In windows forms, u can add controls & raise events(mouse clicks-
handled by event handlers).

7.​ASP.NET:

-​ Is a web development model, which is used to deliver interactive,


data-driven applns over the internet.
-​ It consists of a large no. of controls, such as textboxes, buttons
and labels for assembling, configuring and manipulating code to
create HTML pages.
-​ Asp.net appln can be created by using any CLR-complaint lang
such as VB, C#, VC++&J#.

-​ Features of ASP.NET: better performance, improved security,


greater scalability etc,

AJAX(asynchronous java script and XML):is used as an extension


for ASP.NET to develop &impl. AJAX functionality ASP.NET AJAX as
both client side and server side components to develop the web
applns that can update the info on a web applns without reloading
the page completely.
Advantages of AJAX are: asynchronous, minimal transfer of
data, minimal processing on web server, context.
8.​ADO.NET:

-​ is a tech used for working with data & databases of all types.
-​ It provides access to data sources such as MS SQL server, data
sources exposed through obj linking& embedding
databases(OLEDB) and extensible mark-up Lang(XML).
-​ It is used to connect to data sources for retrieving, manipulating &
updating data
9.​WEB FORMS:
-​ supports the development of robust, scalable web pgs & websites.
-​ Especially ASP.NET applns, using webforms, web pgs can be
created by dragging& dropping controls on to designer then adding
code.
-​ Server controls enable manage new features such as validation,
event-driven, programmatic manipulation of web pgs, state
manipulation etc.
-​ It is tech, which is introduced by MS to provide programming
model for building workflow based applns on windows.
10.​WPF(windows presentation foundation:
-​ MS WPF formerly code named as AVALON.
-​ Provides the base for building applns& a clear separation/w the UI
& the business logic.
-​ WPF helps in building interfaces that includes documents, media,
2&3-dimension graphics, animations and web like characteristics.

-​ WPF is used for creating stand-alone & browser based applns(ex:


yahoo messenger, new york times reader)
-​ WPF introduces a new lang called XAML(extensible appln markup
lang), which is based on XML & is used to design interfaces of WPF
appln.

11.​WCF(windows communication foundation):

-​ Formerly known as IDIGO


-​ Is one of the new tech introduced by MS in .NET framework3.0 for
building and running connected sys.
-​ It is a service-oriented tech for developing applns in distributed
sys.
-​ WCF appln are interoperable with an process as these comm
through SOAP(simple object access protocol msgs.
-​ JSON(javascript object notation) was released with .net
framework3.5 foe supporting serialization format in WCF.
-​ JSON helps WCF service end points to process service requests
from AJAX –powered web pgs.

12.​LINQ(lang integrated query): One of the imp contents of


.netframework4.5 that adds native data querying capabilities to
.net langs by using syntax similar to SQL .

●​ CLS(common lang specification): Specifies a set of rules that need


to be satisfied by lang complier targeting CLR. It helps in
cross-lang inheritance and cross-lang development & debugging.
●​ MEF(manageable extensible framework): is a library to create light
weight
&extensible applns.

❖​VISUAL STUDIO.NET IDE:


▪​ It is an IDE (integrated development environment) provided by MS
to create & develop windows-based. Web-based, console-based &
mobile-based applns in .NET framework.
▪​ The following are the basic components of VS 2012 ultimate IDE:
Start page, menu bar, tool bar, tool box, code editor, intellisense,
designers, solution explorer, properties windows, object browser,
class view, server explorer, component tray, output window, task
list, error list, command window, dynamic help window, manage
style window.
1.​ Start page- first window, when u open VS is the start page.
2.​ Menu bar-provides diff menus from diff VS commands
3.​ Tool bar- short cut to most frequently performed actions. The
options provided in the toolbar can be quickly used as compared to
menus
4.​ Tool box- a window containing a no of nodes & each node contains
a list of controls and components that can be dragged on to a web
form. It is docked on left side of IDE; if it is not visible, u can
access ToolBox from VIEW→menu or by pressing
CTRL+ALT+X keys
5.​ Code editor-code editor window allows u to write & edit u r code
you can use either F7 key or SHIFT+F7 key as toggle to switch
from web forms designer to code editor.
6.​ Intellisense-is an extremely useful feature of VS as you type the
code in the code editor, intellisense provide a list of options for
making lang refers easily accessible and help u in finding the info u
need. It automatically completes typing for u. Makes the writing of
code easier & less proven to errors.
7.​ Designers-a designer is an area in VS, where a windows appln,
web applns or window presentation applns is designed.
●​ It can be used to define the behaviour or appearance of
components and control in design view.
●​ Some of the designers are the
1. windows Forms Designer- enables u to add controls to the
form, arrange them& write code for essential events of the controls
.
2.WPF designer- is a presentation sys for developing windows
clients applns with graphically rich user experiences.
●​ Using WPF, a wide range of both stand alone & and
browser-hosted applns can be create.
●​ The changes made in WPF designer window are automatically
reflected in XAML file.
3.web form designer – enable us to make a changes in the
controls, markup and script of web forms, helps in creating
ASP.NET web applns.
●​ VS 2012 has 3 views in web form designer.
1.​ The design view: displays web pages, master pages, HTML pages
& user controls-allows to add controls in a web form & set their
properties.
2.​ Split-veiw: enable u to view both source view & design view at the
same time.
3.​ Soruce view-displays the markup view of u r page, which includes
HTML elements, ASP.NET controls & client script.
8.​ Solution explorer- displays every project with its reference &
components.
To activate solution explorer in IDE select view→solution
explorer or press CTRL+ALT+L or CTRL+W, S.
9.​ Properties windows- uses to set properties for various objects at
the time of designing a website to view this select,
VIEW→properties window or press F4 or CTRL+W, P keys.
10.​ Object browser- used to examine & find out objects & enums.
To view, select VIEW→object browser or press CTRL+ATL+J
or CTRL+W, J keys.
11.​ Class view- contains a hierarchical tree view representing progs at
the top-level node & displays the classes methods & properties
associated with a particular prog to view select, VIEW→class
view or press CTRL+SHIFT+C or CTRL +W, C keys.
12.​ Server explorer- allows to view the services that are available on a
particular server. To view select, VIEW→server explorer or
press CTRL+W,L. There are two primary nodes in server
explorer.
1.​ Data connections: provide list of data connection that are created
by the user to the server.
2.​ Server: list the currently connected servers that are available for
use.
13.​ Component tray- act as a place holder that contain the
components, time control, added at design time.
14.​ O/p window-display the resources of building & execution applns.
To view select, VIEW→O\P option or press CTRL+ALT+O
keys.
15.​ Task list- displays all tasks that u still have to finish in ur applns.
Help to create and manage a list of pending programming tasks.
●​ To view select, VIEW→task list or press CTRL+T keys.
16.​ Error list- help u to accelerate applns developing by displaying all
the errors in a single window. VIEW→error list or press
CTRL+E keys.
17.​ Command window- u can perform, such as adding a new item to
the program. VIEW→other window→command window or
press CTRL+ALT+A keys
18.​ Dynamic help window- provides links to information found in local
help based on the portion of IDE that is currently in focus.
HELP→view help.
19.​ Manage style window-show all the CSS, files for the web page.
VIEW→manage styles
▪​ NEED OF C # :
●​ C# is one of the intermediate PL used to creat executable
programs.
●​ It is an object oriented PL having many similarities o JAVA, C++ &
VB.
●​ C# combines power and efficiency of c++, simple and clean object
oriented design of JAVA,and the lang simplification of VB.
●​ In additions to its object oriented features, C# provides LINQ
delegates, and lambda express.
▪​ FEATURES OF C # :
●​ Flexible, powerful, easy to use, visually oriented, secure.

You might also like