AGE GEND NDA 0 In Introducti oduction on of of C# C# 0 History - - PowerPoint PPT Presentation

age gend nda
SMART_READER_LITE
LIVE PREVIEW

AGE GEND NDA 0 In Introducti oduction on of of C# C# 0 History - - PowerPoint PPT Presentation

AGE GEND NDA 0 In Introducti oduction on of of C# C# 0 History tory of of C# C# 0 Des esign ign Goals ls 0 Why hy C# C#? : Featu ture res 0 C# C# & Obje ject-Orien Oriented ted Appr proach ch 0 Advan vanta tage ges of


slide-1
SLIDE 1
slide-2
SLIDE 2

AGE GEND NDA

0 In

Introducti

  • duction
  • n of
  • f C#

C#

0 History

tory of

  • f C#

C#

0 Des

esign ign Goals ls

0 Why

hy C# C#? : Featu ture res

0 C#

C# & Obje ject-Orien Oriented ted Appr proach ch

0 Advan

vanta tage ges of

  • f C#

C#

0 Applicat

plications ions of

  • f C#

C#

0 In

Introdu

  • ducti

ction

  • n to

to .Net Net Frame amework work

0 History

tory of

  • f .Net

Net

0 Des

esign ign Featu tures

0 .Net

Net Archite chitectur cture

0 .Net

Net & Obje ject Orien iented ted Appr proach ch

0 Applicat

plication ion of

  • f .NET : GUI

0 Wrapp

pping ng Up Up

0 Refe

ference ces

slide-3
SLIDE 3

IN INTRODUCTIO TRODUCTION N TO TO C# C#

0 C# is

is a mult ulti-par paradig adigm program rogramming ming la langua guage ge which which is is bas ased ed on

  • n objec

ect-

  • rie

ient nted ed and componen mponent-ori

  • rien

ented ted program

  • grammin

ming disc scipl ipline nes.

0 It

It pr provide vides a framewor framework for for free in inter termixi mixing ng cons constr truct ucts fr from

  • m different

different paradigms digms.

0 It

It uses the the “best too tool for for the job” sin ince ce no no one

  • ne pa

paradig adigm solv

  • lves al

all pro problem lems in in the mos

  • st efficien

cient way.

slide-4
SLIDE 4

BR BRIEF IEF HI HISTOR STORY

0 C#

C# wa was dev eveloped loped by by Microso Microsoft ft wit with Ande nders rs Hej Hejlsb sber erg as as th the pr prin incip cipal al de desig igner ner an and lea lead arc archite hitect, ct, wit within hin it its .NET in initiati itiative ve an and it it made made it its appear pearance nce in in 2000 2000.

0 Ande

nders rs Hej Hejls lsber erg an and hi his team eam wanted wanted to to buil uild a new new pr progr

  • gramming

ming languag language that that would would help elp to to wr writ ite cla class ss li librarie aries in in a .NET fram framework

  • work. He

He cla claime imed that that C# C# was much uch closer to to C++ in in its desig ign.

0 The

The na name "C "C sharp sharp" wa was in inspi spired ed by by mu music ical nota notati tion

  • n wh

where ere a sharp sharp in indic dicate ates that the writte ten note sho hould ld be be made de a semit emitone

  • ne highe

her in in pitch ch.

0 Eve

Ever sinc since it its inc ncepti eption,

  • n, C#

C# has has contro controversial sially been een sta stated ted as as an an imi imitation tation of

  • f

Java

  • Java. Howe

However, er, th through

  • ugh th

the co course rse of

  • f ti

time, e, both

  • th Java

Java an and C# C# hav have exhi xhibit ited ed distinct tinct featur tures es which ch suppo upport rt stro trong obje ject-orien iented ted des esign ign principles inciples.

slide-5
SLIDE 5

DE DESIGN SIGN GO GOAL ALS

0 C#

C# was inten ende ded to to be be a simple mple, mode dern, n, obje ject-orien

  • riented

ted langua uage ge.

0 The

The la langua guage ge an and impl implement entati ation had had to to pr provide vide suppo support for for softwar

  • ftware

enginee engineerin ing princip principle les li like stro trong ng type type che checkin cking, g, ar array ay bound

  • unds checking

ecking an and automatic

  • matic garbage

ge collect lection ion.

0 Th

The la langu guag age was was inten intended ed fo for dev evel elopm

  • pmen

ent of

  • f software
  • ftware com

componen

  • nents

ts sui uita table le for deployment ployment in in distrib tributed uted envir ironme

  • nments

ts.

0 Sour

Source code code porta portabili lity was as importa mportant nt for for prog

  • gram

ammers ers wh who were ere fami familia iar with C and C+ C++.

0 Support

port for inter ernali naliza zati tion

  • n to

to adapt pt the soft ftwar ware to to differ ferent ent languag uages es.

slide-6
SLIDE 6

WHY WHY C# ? : C# ? : FE FEATURES TURES

0 C#

C# is is the first “component-oriented” langua guage ge in in the C/ C/C++ ++ fami mily ly.

0 The big idea

ea of

  • f C#

C# is is that everything erything is is an an object.

0 C# is

is a prog rogra ramm mming ing la langua guage ge tha that direct directly ly ref refle lect cts the the un underly derlying ing Co Comm mmon

  • n Langua

anguage ge Infrast frastruct ructure ure (C (CLI LI). Mo Most st of

  • f it

its intrins intrinsic ic ty types es co corres rrespond

  • nd to

to val alue ue-typ types es imp imple lemen mente ted by by the CLI frame amework rk.

0 Type

Type-sa safe fety ty: C# C# is is more more typ type sa safe fe tha than C+ C++. Type Type sa safe fety ty is is the the ex exte tent to to wh which ich a progra gramm mming langu guag age discoura

  • urage

ges or

  • r prevents

events type errors

  • rs.

0 C#,

#, like C++, but unlike ike Java, va, support

  • rts operat

rator

  • r overl

erloa

  • ading

ing.

0 Ma

Manag aged memory

  • ry is

is aut autom

  • mat

atica call lly ga garbag age co coll llec ecte

  • ted. Garb

arbag age col

  • lle

lect ctio ion ad addre dresse ses the the pro roble lem of

  • f mem

emory

  • ry le

leak aks by by fre freeing eing the the prog rogramm rammer er of

  • f res

responsi

  • nsibil

ilit ity for for rel relea easi sing memory emory that is is no no longe ger needed eded.

0 C#

C# provi rovides des prop

  • pert

ertie ies as as synta syntact ctic sug sugar ar for for a comm

  • mmon
  • n pat

atte tern rn in in wh which ich a pai air of

  • f met

ethods, hods, acc ccess ssor

  • r (g

(get ette ter) and and muta utato tor (s (set ette ter) en enca capsu sula late te op

  • pera

erati tion

  • ns on
  • n a si

singl gle at attri tribute ute of

  • f a

class.

slide-7
SLIDE 7

WHY WHY C# C# ? : ? : FEATURES …cont.

0 In

In addit addition ion to to th the try... ..ca catch tch cons construct uct to to handle handle excepti xceptions

  • ns, C#

C# ha has a try try... ...fi final ally ly cons construct uct to to gua guaran antee tee ex executi ecution

  • n of
  • f the

the code code in in the finally lly block, k, wheth ether er an an excep ception ion occurs curs or

  • r not.

0 Unlike

Unlike Java, Java, C# C# do does no not have have check checked exc exceptions

  • eptions. This

his ha has been een a consci nsciou

  • us decis

ision ion based on

  • n the issue

ues of

  • f scalability

lability and ver ersi sion

  • nab

abilit ity.

0 Mult

Multip iple le in inherita eritance nce is is not not suppo supported ted, al alth though

  • ugh a cla

class ss can impl implement ent any ny num number er of

  • f inte

interface

  • faces. Thi

his was as a de desig ign decision ion to to avoid avoid compl complic icati ation and nd simp mplify ify architectur hitectural al requi equirem rements ents througho ughout CLI CLI.

0 C#

C# suppo supports a strict trict Boolean Boolean dat data type, type, boo

  • ol. Sta

State tements ments that that take take condi conditi tions

  • ns, such

ch as as while while and nd if, f, req requir uire an an exp expressio ssion of

  • f a type

ype that that implem plements ents the true ue opera erator tor, such ch as as the boolea ean type.

slide-8
SLIDE 8

C# C# & O & OBJECT JECT ORIENTED IENTED APPRO PROACH CH

(I)

Structs ucts & Cla Classes

(II) I) Interf

erfaces aces

(III) II) Dele

lega gates tes

(IV IV)Swit

itch ch Statement: tement: Fall ll Th Throug ugh

(V) For Each:

ch: Co Contr trol l Flo low

(VI VI)Vir

irtu tual al Methods hods

(VI VII)Boxi

xing g & Unboxi xing ng

(VII VIII) I)Co

Common

  • n Ty

Type System

(IX IX)Generi

nerics cs

(X) Refle

lect ction ion

slide-9
SLIDE 9

(I (I) STR ) STRUCTS CTS & CL CLAS ASSE SES S IN IN C# C#

0 In

In C# C# structs structs are re very very diffe ifferent rent fr from

  • m cla

class sses

  • es. Structs

Structs in in C# C# are re des design gned to to enca encapsulate psulate lig ightwe htweigh ght obje jects

  • cts. They

They are va value lue types types (not

  • t re

reference ference ty types pes), so so they' y're re passed sed by by value.

0 They are sealed,

ed, whic ich means ns they cann nnot

  • t be

be deriv ived ed from or

  • r have any base class

ss.

0 Classes

sses in in C# C# are dif iffere erent nt from classes sses in in C++ in in the followi

  • wing ways

ys:

i. i.

Ther There is is no no access ccess mod modifier ier on

  • n the

the name name of

  • f the

the base se cla class ss and nd inh nher erita tance nce is is always lways public ic.

ii. ii.

A cla class ss ca can on

  • nly

ly be be der derive ived fr from

  • m on
  • ne base

se cla lass

  • ss. If

If no no ba base se cla class ss is is exp explicitly tly specifie cified, d, then the class ss wil ill automa matica tically lly be be deriv ived ed from System tem.Ob Obje ject ct.

iii. iii.

In In C++ ++, the the on

  • nly

ly ty types pes of

  • f cla

class ss mem members ers are re va varia iables, les, funct function ions, s, cons constructors, tructors, de destructor structors and nd ope perat rator ove verl rloa

  • ads,

ds, C# C# also lso pe perm rmits its de delega legate tes, s, ev events ents and nd propert erties ies.

iv. v.

The access ess modif ifie iers rs public ic, priv ivate te and protect ected ed have the same me meani ning g as in in C++ but t there re are two addit itio ional nal acces ess s modif ifie iers rs avail ilable: e: (a (a) I Internal ernal (b (b) Protec ecte ted d in internal nal

slide-10
SLIDE 10

(I (II) I) IN INTE TERF RFACES CES

0 C# does

es not suppo upport rt Multi tiple ple In Inheri eritan ance ce

0 Howeve

wever r a class s can imple leme ment nt numb mber er of inter erfaces faces

0 It

It conta tain ins s meth thod

  • ds,

s, proper

  • perti

ties, es, indexe exers rs, , and events ents inter erfa face ce DataBin aBind { void d Bind( d(IDataBi IDataBinde nder bind); ); } Class ass Edit itBo Box: Contr trol,

  • l, DataBi

aBind nd { void d DataBi aBind. nd.Bind Bind(IDat IDataBin aBinder der bind) {…} }

slide-11
SLIDE 11

(I (III II) ) DELEG LEGATES TES

0 A dele

lega gate te is is sim imila ilar r to a functi ction n poin inter ter in in C/C#. #.

0 Usin

ing g a dele lega gate te allo llows a programmer grammer to enca caps psula ulate te a refer erenc nce to a method hod in insid ide a dele lega gate te obje ject ct, , whi hich ch ca can the hen n be passed ed to co code.

0 Decla

clari ring ng a dele legat gate: e: public blic dele lega gate te vo void id BookDe Delegate legate(B (Boo

  • ok book);

0 Instantiati

antiating ng a dele lega gate: te: book.P .Paper aperback backBoo Books(new (new BookDele Delegate gate(Tit (Title)); le));

0 Calli

lling g a dele lega gate: te: pro roce cessBo ssBook(b); (b);

slide-12
SLIDE 12

(IV IV)SW )SWITCH ITCH ST STATE TEMEN MENT: : FALL LL THR THROU OUGH GH

0 In

In C# C# a switch tch state temen ment t ma may not "fall throug

  • ugh"

h" to the next state temen ment if it does s any work. k. To accompl mplis ish h this, , you need ed to use an expli licit it goto goto state temen ment: switch tch (i) { case 4:Cal allF lFun uncOn cOne( e(); ); goto goto case 5; 5; case 5: 5: CallS lSomeFunc

  • meFunc()

(); } If If the e case state temen ment t does es not work rk (has as no code e within hin it) ) then en you can fall : switch tch (i) { case 4: // fall fall throug

  • ugh

case 5: 5: CallS lSomeFunc

  • meFunc()

(); }

slide-13
SLIDE 13

(V)F

)FOR OR EACH CH CO CONTR TROL OL FL FLOW W

New contro trol flow statem atement ent- for

  • reach

ch : C# pro rovide vides an an addit addition ional flow low contro control stat tatem emen ent, t, for for each

  • each. Fo

For each each loop loops acr cross ss al all it item ems in in arr array ay or

  • r collect
  • llection

ion wi with thout

  • ut req

requirin uiring expli explici cit speci specifi ficati ation

  • n of
  • f

the indice ces. Sy Syntax: Foreach ch(do (doub uble le som

  • meEle

leme ment nt in in MyArray ay) { Console

  • nsole.Writ

iteLi eLine( ne(som someEl eElem ement) ent); }

slide-14
SLIDE 14

(V

(VI) I)VI VIRTU TUAL AL ME METHOD THODS S

0 In

In C C# one can choose to to override a virtual functi tion

  • n from base cla

lass. . Derived d method

  • d can participate

cipate in poly lymor morphism phism only ly if it uses the keyword rd override de before it.

0 In

In C++, , if provided ded the same e syntax ax method

  • d in derive

ved d cla lass as base cla lass virtual al method

  • d, it will

ll be a automa mati tica call lly be o

  • verridd

dden. en.

0 In

In C# we have abstract ct methods

  • ds and in C++ pure virtual methods.
  • ds. Both may not be

exactly tly same, , but a are equival alent nt (as pure virtual al can have funct ction n body)

0 EXAMPLE

LE: cla lass Base{ e{ publi lic virtual l string g VirtualM lMethod thod() () { { return "base virtual" l"; } ; } } cla lass s Deriv ived ed : Base{ { publi lic override e string g Virtual alMet ethod hod() () { { return "Derived d override den" n"; } ; } }

slide-15
SLIDE 15

(VI VII) I)BO BOXING XING AN AND UNBO D UNBOXING XING

0 Boxing

xing is the e oper erati ation

  • n of conve

verti ting g a value ue-ty type pe obje ject into a value ue of a corres respond pondin ing refer ference ce type. e.

0 Boxing

xing in C# C# is impl plic icit. t.

0 Unboxing

ing is the e operation eration of convert verting ng a value ue of a refer ference ce type e (prev eviou

  • usl

sly boxed) d) into a value ue of a value ue type. e.

0 Unboxing

ing in C# requ equire ires s an explicit plicit type e cast.

  • t. A boxed

d obje ject of type e T can only be unboxed xed to a T (or a nullab lable le T). ).

0 EXAMP

MPLE LE : int box_var var = 42; // // Value ue type.

  • bje

ject bar = box_var; var; // / foo is boxed ed to bar. int box_var var2 2 = (int)b )bar; // Unboxed xed back to value ue type. e.

slide-16
SLIDE 16

(VI VIII II)COMM )COMMON N TY TYPE PE SY SYSTE STEM

0 C#

C# ha has a uni unified ied type type system

  • tem. This

his uni unifi fied ed type type syst ystem is is cal called led Common

  • mmon

Type pe System tem (CTS TS).

0 A uni

unified ied type type syste tem im impl plie ies that that al all type ypes, s, in includin cluding primi imiti tive ves such such as as integ ntegers ers, ar are su subcla lass sses of

  • f the

the Sy Syste tem.Obje ject ct cla class

  • ss. For
  • r exampl

example, e, ev ever ery type type inheri erits ts a ToString String() () meth thod

  • d.

0 CTS

S separ eparates ates data types es into two categ egories

  • ries:
  • 1. Value

ue types es

  • 2. Refer

eference ence types es

slide-17
SLIDE 17

(VI VIII II)V )VAL ALUE UE TY TYPE PE V/ V/S S RE REFER FERENCE ENCE TY TYPE PE

VALU LUE TYPE PE:

0 Instan

Instances ces of

  • f val

value ue ty type pes do do not not have have ref refer eren ential tial iden identit ity nor nor ref efer eren ential tial com compar parison

  • n se

semantics mantics i.e. eq equality uality and nd in inequal quality ty comparis comparisons

  • ns for

for val value type types com compare pare th the actua ctual data data va valu lues wit within hin the the insta nstance nces, s, unl unless ss the he co corr rrespondi

  • nding

ng

  • perato

erators rs are overl erload

  • aded

ed.

0 Val

alue ue type types are are derived ived fr from

  • m Sy

System em.Value lueType Type, al alwa ways ys have have a default default value ue, and can always ys be be created eated and copied ied.

0 They

They cann cannot

  • t derive

ive fr from

  • m each

each other

  • ther (but can

can imple mplement ment inte interface faces) an and cannot

  • t have

ve an an expli plicit it defaul fault (param ameter eterles less) constr nstructor tor.

slide-18
SLIDE 18

(VI VIII II) ) VAL ALUE UE TY TYPE PE VS VS REFERENCE TYPE …cont.

REFERENC FERENCE TYPE PE:

0 Ref

Refer eren ence ce ty type pes hav have the he no noti tion

  • n of
  • f refe

eferenti rential id iden entit ity - each each in instan stance ce of

  • f a

ref eferen erence ce typ type is is in inhe heren rently ly distinct distinct fro from ev every other

  • ther in

instan tance ce, even ven if if the the data within in both instanc ances is is the same ame.

0 It

It is is not not al alway ays po possib sible le to to create create an an in instan tance ce of

  • f a refer

eferen ence ce ty type pe, nor nor to to cop copy an an exi existing ng instance, nstance, or

  • r perform

form a val value ue co compar mparison

  • n on
  • n two

two exi xisti ting insta tance nces.

0 Specific

Specific ref eferen erence ce type types ca can pr provide vide se service vices by by expo exposin ing a pu public ic cons constr tructor uctor

  • r
  • r

impl implementi menting a corre correspo pondi ding ng in inte terface face (suc uch as as IC IClonea

  • neable

le orICom Compar parab able). Example amples: System tem.Str tring ng, System tem.Ar Array ay

slide-19
SLIDE 19

(I (IX) X)GENE GENERICS RICS

0 Generic

rics use ty type pa para rameters ters, whic ich make i it p t possibl ible to to desig ign classes s and meth thods t that t do not t specif ify t the t type used unti til t the class or m r meth thod is is i insta tanti tiated ted.

0 The main

in a advan vanta tage ge is is t that t one c can use generic ric ty type pa para rameters ters to to cre reate te classes s and meth thods th that t can be us used wit ithout in t incurrin rring th the c cost t of ru f runti time casts ts or bo r boxin ing opera rati tions.

0 EXAMPL

PLE: public ic c class Generic ricLis ist<T <T> { void id Add(T in input) { { } } } } class TestGe tGeneric ricLis List { { priv rivate te class ExampleClass ss { } } sta tati tic void id Main in() { // // Declare re a lis ist o t of ty f type i int. t. Generic ricLis ist<in int> lis ist1 t1 = n new Generic ricLis ist<in int>(); // // Declare re a lis ist o t of ty f type strin string. Generic ricLis ist<stri tring> lis ist2 t2 = n new Generic ricLis ist<stri tring> g>(); } }

slide-20
SLIDE 20

(X (X) ) RE REFLE FLECTIO CTION

0 Refl

flecti ection

  • n is useful

eful in the e followin

  • wing

g situat tuations ions:

0 When

hen you u need ed to access ess attrib ibutes utes in your ur program'

  • gram's

s metadat tadata.

  • a. See

e the e topic ic Access cessing ing Attri tributes utes With th Ref efle lecti tion.

  • n.

0 For exami

amining ning and insta tantiating ntiating types es in an assem embly. y.

0 For building

ng new types es at runti ntime me. . Use e classe ses s in in System tem.Re Refle lect ction.Emi ion.Emit. t.

0 For performin

forming late binding, g, access essing ing metho thods s on types es created eated at run n time. me.

0 EXAMP

MPLE LE: // // Using ng GetType tType to to obtain type infor

  • rmatio

mation: int int i = 42 42; System tem.Type Type type = i.GetType GetType() (); System tem.Cons Console.W

  • le.WriteL

riteLine ne(ty (type pe); );

slide-21
SLIDE 21

ADVANT ANTAGES GES OF C# C#

0 It all

llows desig ign n tim ime and run tim ime attribu bute tes s to be in incl clude ded. d.

0 It all

llows in integra grated ted docu cumentation ntation usin ing g XML ML.

0 No header

r fil iles, , IDL etc.

  • c. are r

requir ired ed.

0 It ca

can be embedded d in into

  • web pages.

0 Garbage

ge co coll llection ction ensures s no memory le leakage e and stray poin inte ters. rs.

0 Due to exce

cepti tion

  • ns,

s, error handling dling is is w well ll-planne planned d and not t done as an an aftertho rthought. ught.

0 All

llows s provi visi sion

  • n for in

intero roper erabi bility. lity.

slide-22
SLIDE 22

AP APPLIC PLICATIO TIONS NS OF OF C# C#

0 The

he three main n types es of appli licatio ation n that can be written tten in C# are: e:

1. 1.

Winform forms - Windows ndows like ke Forms. ms.

2. 2.

Conso nsole le - Comm mmand nd line In Input t and Outpu put. t.

3. 3.

Web eb Sites es : Web eb sites tes need ed II IIS (Micr crosoft's soft's web ser erve ver) r) and ASP. P.NET.

slide-23
SLIDE 23

IN INTR TRODUCTIO ODUCTION N TO .N TO .NET T FR FRAM AMEW EWORK ORK

0 .NET fra

frame mework work is is a software software fram amewo ework rk primar maril ily for for Microso Microsoft ft Windows

  • Windows. It

It incl nclude udes a la larg rge lib library ary & pr prov

  • vid

ides la lang nguag uage in intero teroper erabili lity acros across seve veral al progr

  • gram

amming ng langua uages ges.

0 Program

Programs writ itten ten fo for th the .NET Fram amewo ework rk ex execut ecute in in a softwar

  • ftware envi

environm

  • nment,

ent, as as op

  • pposed to

to a har hardwa dware one

  • ne for

for most most oth

  • ther progr
  • grams. Co

Commo mon ex example amples of

  • f

such uch progr

  • grams

ams include ude Visua ual Studio, dio, Team eam Explore lorer UI, I, Sharp arp Develop velop .

0 Program

Programmers ers com combin ine th their eir own

  • wn sour

urce cod

  • de wit

with th the .NET NET Frame amework work an and

  • th
  • ther lib

librar rarie

  • ies. The

he .NE NET Fram ramework ework is is in inten tended ded to to be be used ed by by mo most st ne new applicat lications ions created eated for the Windo dows ws platform form.

slide-24
SLIDE 24

HI HISTO STORY Y OF OF .N .NET

0 .NET wa

was develo eveloped ped by by Microso Microsoft ft in in the the mid mid 199 1990s, s, origina iginall lly und under er th the name me of

  • f ‘Next Gener

nerati tion

  • n Windo

dows ws Services vices’.

0 .NET 1.1 was

was th the fi first rst ve version rsion to to be be in included cluded as as a part art of

  • f th

the Windows Windows OS

  • OS. It

It prov

  • vided

ded built uilt-in in suppo support fo for AS ASP .NET, ODBC ODBC & Oracle Oracle dat databas

  • ases. It

It pr provid

  • vided

ed a highe higher lev evel el of

  • f tr

trust st by by allowing allowing the the use ser to to en enable le Code de Access cess Security curity in in ASP. NET.

0 Cu

Curren rentl tly, Win indo dows 8 sup suppo ports version ersion 4.5 of

  • f .NET

NET which hich sup uppo ports provis

  • vision

ion for ‘Metro St Style Apps’

slide-25
SLIDE 25

DESI SIGN GN FE FEATURES TURES

0 In

Inte teropera

  • perability

ility: .NET NET Fra ramewor mework provide provides mean eans to to acce ccess ss funct function ional ality ty impl implemented mented in in newe newer an and older

  • lder program

programs that that ex execut ecute out

  • utsid

ide the the .NET ET en environm vironmen ent. Acce Access to to COM COM compo compone nent nts is is pro rovide vided in in the the Syste ystem.Runtime Runtime.Inte nterop

  • pSe

Service vices an and Sy Syste tem.Enterp nterpriseS eServi ervice ces namespa mespace ces of

  • f the frame

amewor work.

0 Com

Commo mon La Lang ngua uage ge Runtim Runtime eng engin ine: CL CLR serves as as th the ex executi ecution

  • n en

engin ine of

  • f

the the .NET NET Fram amewo

  • ework. All

ll .NET NET progr programs ams exec execute ute under nder th the supe supervi vision ion

  • f
  • f the

the CL CLR, R, gua guaranteeing anteeing cer certai tain pr prope

  • perti

ties an and beh ehav aviors iors in in the the area areas of

  • f

memo emory ry manag agem ement, ent, secu curit ity, y, and exce cept ption ion handling dling.

0 Lang

nguag uage Indep ndepen endence dence: .NET ET Fram ramework ework in intro trodu duce ces Com

  • mmon

mon Ty Type Syste ystem which hich defin define al all po possi ssible le data data type types & program programming ming co constructs nstructs suppo supported ted by by CL CLR & rule uled fo for th their eir in interaction teraction as as per er CLI CLI specificati ecification

  • n.

Th This al allows lows the the exchange exchange of

  • f type

types & obje ject ct in instan tances ces between etween li librarie aries & their eir applications ications written tten using ing any conform

  • rming

ng .NE NET langua uage ge.

slide-26
SLIDE 26

DESI SIGN GN FEATURES …cont.

0 BCL

BCL: It It is is a lib library ary of

  • f funct

functio iona nalit ity which which is is avai available le to to all ll lan anguage guages usin ing the the Fr Framewor

  • mework. It

It cons consists of

  • f cla

classe sses, s, in interface terfaces or

  • r reu

reusable le type types that that integr grate te with CLR LR.

0 Porta

Portabili lity: The The fra framew mework

  • rk al

allows lows pl platform tform-ag agnos nostic & cross ss-pl platform tform impl implementa mentations ions for for oth

  • ther OS’.

The he ava vail ilability lity of

  • f speci

specifica icati tions

  • ns for
  • r th

the CL CLI, & C# C# ma make ke it it pos possible le for for thi third par parti ties to to crea create te co compa patib tible le implem plement entatio ations ns of

  • f the frame

amework work & it’s langua uages ges on

  • n other

her platfor forms.

slide-27
SLIDE 27

.N .NET T FR FRAM AMEW EWORK ORK AR ARCHI CHITECTURE TECTURE

slide-28
SLIDE 28

.N .NET ET ARCHITECTURE CHITECTURE DE DESIGN SIGN

CLR:

0 The software environment in which programs for .NET framework run is known as the ‘Common

Language Runtime’. It is Microsoft’s implementation of a ‘Common Language Infrastructure’. Its purpos

  • se is to provi

vide de a lang nguag uage-neu neutral ral platfor

  • rm

m for appli lica cation

  • n develop

lopme ment nt & execution

  • n.

0 The CLI

I is respon

  • nsible for except

ption

  • n handli

dling ng, garbag age collect lection

  • n, security & interop
  • perab

rability. y.

0 The CIL

IL code is housed d in CLI I assemb mblies.

  • s. The assemb

mbly consi sist sts s of ma many files, one of which mu must contai ain n me metadata data for assemb mbly. y. VM VM:

0 An appli

licat cation

  • n VM provide

des s services s such as security, me memo mory ma manag ageme ment nt & except ption

  • n handli

ndling ng.

0 The security me

mechani nism sm suppor

  • rts 2 ma

main features.

0 Code Access

s Security: y: It It is based on proof

  • f that is related

d to a specific assemb

  • mbly. It

It uses the same me to determi mine ne permi mission

  • ns gran

anted d to the code.

0 Validat

dation

  • n & Verification
  • n: Validat

dation

  • n determi

mine nes s whether the code satisfies s specified d requirements ments and d Verification

  • n determi

mines nes whether the condi dition

  • ns

s imp mposed d are satisfied d or not.

slide-29
SLIDE 29

.N .NET T AR ARCHI CHITECTURE TECTURE DESIGN …cont.

Class ss Lib ibrary: y:

0 The class

ss lib ibrary & CLR essen sentia tially lly constitut stitute e the .NET T Framew ework rk. . The Framework’s base class library provides UI, data access, database connectivity, algori rithms, thms, netwo work rk communicatio munications ns & web a applicat icatio ion n develo lopment. pment.

0 In spit

ite of the varie ied functio ctionality, nality, the BCL in includes des a small ll subset t of the entir ire e class ass lib ibrar ary & & is is t the core e set of classes sses that at serv rve e as as the bas asic ic API of the CLR.

0 The Framew

ework rk Class ss Lib ibrary y is is a superset erset of BCL & refers rs to the entir ire class ss lib ibrary whic ich h in include udes s lib ibrarie ies s for ADO.N DO.NET ET, , ASP.NE .NET, T, Win indows

  • ws Forms
  • rms,

, etc.

0 It is

is much h larger er in in s scope pe compa pared red to C++ & comparab rable to lib ibrarie ies s in in J Java.

slide-30
SLIDE 30

.N .NET T AND OB OBJEC JECT- OR ORIE IENTED NTED APPRO PROACH CH

0 Mem

Memor

  • ry managem

management ent in in .NET Framewo amework rk is is a cruci crucial al as aspect ect.

0 Mem

Memor

  • ry is

is al alloca located ted to to in instant ntia iations ions of

  • f .NET

NET obj

  • bjec

ects ts from th the managed managed heap heap, a po pool

  • l of
  • f memory

mory man manag aged ed by by the the CLR

  • CLR. As

As lon long as as the here re exi exists a ref eferen erence ce to to an an object ject, eit either a dir direct ect ref referen rence ce or

  • r via

via a graph, graph, th the object ect is is considered nsidered to to be be in in use.

0 When

hen th there ere is is no no ref eferen erence ce to to an an obj

  • bjec

ect, t, an and it it cann cannot

  • t be

be rea reached ched or

  • r used,

sed, it it become mes garbage, e, eligib ible for collectio lection

0 NE

NET Fram ramework work in incl clude udes a gar arbage ge coll collector ector which hich runs ns perio eriodically dically, on

  • n

a separ parate ate th thread ead from th the appl applica icati tion'

  • n's thread,

thread, that that enume numerate ates al all the the unusabl usable obje jects ts and recla claims ims the memo emory ry allocated cated to to them em.

slide-31
SLIDE 31

GARB ARBAGE GE CO COLL LLECTIO ECTION

slide-32
SLIDE 32

GARBAGE COLLECTION…cont.

0 Each

ach .NET NET appl application ication ha has a set set of

  • f roo
  • ots,

s, which hich ar are poi

  • inter

nters to to objects ects on

  • n

the the mana managed ged heap heap (mana managed ged obj

  • bjec

ects ts). The hese se may may be be ref eferen erence ces to to stati tatic

  • bjects

cts, objects ects defin defined ed as as loc local al varia variable les or

  • r met

metho hod pa param amete eters rs curr urrently ently in in scop

  • pe, obje

jects ts refer ferred red to to by by CPU regi giste ters

0 When

hen th the GC GC run runs, s, it it pau pauses th the appl applic icati tion,

  • n, an

and for for each each object ect refer ferre red to to in in th the roo

  • ot, it

it recu recursivel rsively col collect lects al all th the obj

  • bjec

ects ts rea each chable le from

  • m the

he roo root

  • bje

jects ts and marks them em as as reachab achable.

0 It

It use ses CLI CLI metada etadata ta an and ref reflect lectio ion to to disco discover the he objects ects enca encapsul ulated ted by by an an object, ect, an and th then en rec ecursiv ursively wal walk th them

  • em. It

It th then en en enum umerates ates al all the the objects ects on

  • n

the the heap eap (w (which hich were ere initial initially ly al alloc located ated con contiguou tiguously ly) usin ing ref reflect lection

  • ion. All

ll

  • bje

jects ts not marked ed as as rea eachabl chable are garbage ge.

slide-33
SLIDE 33

GARBAGE COLLECTION…cont.

The The GC GC use sed by by .NET NET Fr Fram amewo ework is is actual ctually ’generational’. Objects ects ar are as assigned igned a ge generation neration; newl newly crea created ted objects ects belong elong to to ’Gen Gener erati ation

  • n 0’. The

he

  • bjects

cts that hat sur survive vive a ga garbag age collect collection ion are are tag tagged ged as as ’Generation eneration 1’, an and the the Gen enerati eration

  • n 1 objects

ects that that survive rvive ano noth ther er coll collect ectio ion are re ‘Gen Generati eration

  • n

2’ obje jects

  • ts. The .NE

NET Frame amework work uses es up up to to Genera eration ion 2 obje jects ts.

slide-34
SLIDE 34

GU GUI I AP APPL PLICA ICATIO TIONS NS USI SING G C# C# & .N .NET

0 Windows

dows form is is used ed to to crea eate te applicati lications

  • ns with a user

er inter erface ace.

0 The

he following lowing are the steps eps to to crea reate te a Windows ndows Form rm Appli lica cati tion

  • n:
  • i. Open a new Project
  • ject and choo
  • ose

se the Windows ndows Form Appl plication ication ii ii.Sta Start dr drag aggi ging component components from the he To Tool

  • lbox
  • x to

to th the Form

  • rm. The fo

form wil will look

  • k som
  • meth

ething ng like ke this is:

slide-35
SLIDE 35

GU GUI I AP APPL PLICA ICATIO TIONS NS USI SING G C# C# & . .NET …cont.

  • iii. As compo

mponen nents ts are e added ded to the e Form, m, Visua ual l Studio dio assig igns ns defaul ault t names mes to each h one.

  • e. It

It is via these ese names mes that t any C# code de will inter eract ct with h the e user er inter erface ace of the e application ication.

  • iv. The

he name me of thes ese e componen mponents ts can be chang nged ed in the Pro roper perti ties es panel v. . In In additi tion

  • n to changing

ging the e names mes of compo mponen nents ts it is also

  • pos
  • ssib

sible le to chang nge e a myri yriad ad array y of

  • f

differe ferent t prope

  • perties

rties via the e prope

  • pertie

ies panel el.

slide-36
SLIDE 36

GU GUI I AP APPLIC PLICATIO TIONS NS US USIN ING G C# & .NET …cont.

  • vi. Addin

ding g behavio avior r to a Visual ual Studio dio C# application: ication: The he next xt task sk in crea reating ting our ur application lication is to add some

  • me funct

ction ionali lity y so

  • that

t thing ngs happe pen when en we press ess the e two buttons ns in our ur form.

  • m. This

is behavior vior is contro troll lled ed via events.

  • ents. For example

ample, , when en a button n is press essed d a Click ck even vent t is trigger gered. d.

slide-37
SLIDE 37

GU GUI I AP APPL PLICA ICATIO TIONS NS USI SING G C# & .NET …cont.

0 Co

Codes des can be be added ded for on

  • n Button

tton Cl Click ck even ents

  • ts. So

Some me examp ample les are: (I) I) private vate void closeButton utton_C _Click ick(obj (object ct sender, ender, EventArg entArgs e) e) { Clos

  • se()

(); } (II II) private vate void hello lloButton_Cl ton_Click ck(obj (objec ect sende nder, r, EventAr entArgs gs e) { welcome comeTe Text xt.Tex ext = "H "Hell llo " + nameTe meText xt.Text xt; }

slide-38
SLIDE 38

AD ADVANT ANTAGES GES OF OF .N .NET

0 Pla

latform

  • rm in

independe pendent nt

0 Support

ports mult ltip iple le programmi gramming ng la langu guages ages

0 Easy to deplo

loy

0 Support

ports va vario ious us secu curity ity feature tures s such ch as cr cryptography, ptography, appli plica cati tion

  • n domain,

in, ve verific ificatio ation n process cess etc. c.

slide-39
SLIDE 39

WR WRAP APPING PING UP

0 Intr

trod

  • duced

ced basic ic co concept cepts s of C# progra ramming ng.

0 Dis

iscu cusse sed d sim imila ilaritie ties s and diff ifference ences s between n C# C# & & othe her progra rammin ming la language ages s (C,C++,Ja +,Java va). ).

0 Dis

iscu cusse sed d Obje ject ct-Or Orient iented ed behavi viou

  • ur of C#.

0 Intr

trod

  • duced

ced co concept cepts s rela lated d .NET framewor

  • rk.

0 Expla

lain ined d .NET arch chite tectur cture. e.

0 Shed li

light ht upon Obje ject ct-Orien Oriente ted d approach ch in in .NET f framewor

  • rk.

0 Adva

vant ntage ges s & Appli lica catio tions ns of C# and .NET.

slide-40
SLIDE 40