c and Aspnet Faqs

download c and Aspnet Faqs

of 55

Transcript of c and Aspnet Faqs

  • 7/26/2019 c and Aspnet Faqs

    1/55

    C# and ASP.Net FAQ

    NET FrameWork FAQ's

    When was .NET announced?

    Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 P!

    had a num"er o# sessions on .NET te$hnology, and delegates %ere given !s $ontaining a &rerelease version o#

    the .NET #rame%ork()* and +isual )tudio.NET.

    When was the first ersion of .NET re!eased?

    The #inal version o# the .0 )* and runtime %as made &u"li$ly availa"le around -&m P)T on Jan2002. /t thesame time, the #inal version o# +isual )tudio.NET %as made availa"le to )N su"s$ri"ers.

    What "!atforms does the .NET Framework run on?

    The runtime su&&orts 1indo%s P, 1indo%s 2000, NT3 )P-a and 1indo%s E(45. 1indo%s 4 is not su&&orted.

    )ome &arts o# the #rame%ork do not %ork on all &lat#orms #or e6am&le, /)P.NET is only su&&orted on 1indo%s

    P and 1indo%s 2000. 1indo%s 45(E $annot "e used #or develo&ment.

    77) is not su&&orted on 1indo%s P 8ome Edition, and so $annot "e used to host /)P.NET. 8o%ever, the

    /)P.NET 1e" atri6 %e" server does run on P 8ome.

    The ono &ro9e$t is attem&ting to im&lement the .NET #rame%ork on :inu6.

    What is the C$?

    !:; < !ommon :anguage ;untime. The !:; is a set o# standard resour$es that =in theory> any .NET &rogram $an

    take advantage o#, regardless o# &rogramming language. ;o"ert )$hmidt =i$roso#t> lists the #ollo%ing !:;

    resour$es in his )N P!? arti$le@A"9e$toriented &rogramming model =inheritan$e, &olymor&hism, e6$e&tion handling, gar"age $olle$tion>

    Security model

    Type system

    All .NET base classes

    Many .NET framework classes

    Development, debugging, and profiling toolsEecution and code management

    !"#to#native translators and optimi$ers

    1hat this means is that in the .NET %orld, di##erent &rogramming languages %ill "e more eual in $a&a"ility than

    they have ever "een "e#ore, although $learly not all languages %ill su&&ort all !:; servi$es.

    What is the CTS?

    !T) < !ommon Ty&e )ystem. This is the range o# ty&es that the .NET runtime understands, and there#ore that.NET a&&li$ations $an use. 8o%ever note that not all .NET languages %ill su&&ort all the ty&es in the !T). The

    !T) is a su&erset o# the !:).

    What is the CS?

    !:) < !ommon :anguage )&e$i#i$ation. This is a su"set o# the !T) %hi$h all .NET languages are e6&e$ted to

    su&&ort. The idea is that any &rogram %hi$h uses !:)$om&liant ty&es $an intero&erate %ith any .NET &rogram

    %ritten in any language.

    7n theory this allo%s very tight intero& "et%een di##erent .NET languages #or e6am&le allo%ing a !? $lass to

    inherit #rom a +B $lass.

    What is %?

    7: < 7ntermediate :anguage. /lso kno%n as )7: =i$roso#t 7ntermediate :anguage> or !7: =!ommon

    7ntermediate :anguage>. /ll .NET sour$e $ode =o# any language> is $om&iled to 7:. The 7: is then $onverted to

    ma$hine $ode at the &oint %here the so#t%are is installed, or at runtime "y a Just7nTime =J7T> $om&iler.What does 'mana&ed' mean in the .NET contet?

    The term 'managed' is the $ause o# mu$h $on#usion. 7t is used in various &la$es %ithin .NET, meaning slightly

    di##erent things.anaged $ode@ The .NET #rame%ork &rovides several $ore runtime servi$es to the &rograms that

    run %ithin it #or e6am&le

    e6$e&tion handling and se$urity. For these servi$es to %ork, the $ode must &rovide a minimum level o# in#ormation

    to the runtime.

    )u$h $ode is $alled managed $ode. /ll !? and +isual Basi$.NET $ode is managed "y de#ault. +)C !DD $ode is not

    managed "y de#ault, "ut the $om&iler $an &rodu$e managed $ode "y s&e$i#ying a $ommandline s%it$h =($omD>.

    Managed data@ This is data that is allo$ated and deallo$ated "y the .NET runtime's gar"age $olle$tor. !? and

    +B.NET data is al%ays managed. +)C !DD data is unmanaged "y de#ault, even %hen using the ($omD s%it$h, "ut

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1

  • 7/26/2019 c and Aspnet Faqs

    2/55

    C# and ASP.Net FAQ

    it $an "e marked as managed using the g$ key%ord.anaged $lasses@ This is usually re#erred to in the $onte6t o#anaged E6tensions =E> #or !DD. 1hen using E !DD, a $lass $an "e marked %ith the g$ key%ord. /s the

    name suggests, this means that the memory #or instan$es o# the $lass is managed "y the gar"age $olle$tor, "ut it

    also means more than that. The $lass "e$omes a #ully &aidu& mem"er o# the .NET $ommunity %ith the "ene#its

    and restri$tions that "rings. /n e6am&le o# a "ene#it is &ro&er intero& %ith $lasses %ritten in other languages #or

    e6am&le, a managed !DD $lass $an inherit #rom a +B $lass. /n e6am&le o# a restri$tion is that a managed $lass $an

    only inherit #rom one "ase $lass.

    What is ref!ection?/ll .NET $om&ilers &rodu$e metadata a"out the ty&es de#ined in the modules they &rodu$e. This metadata is

    &a$kaged along %ith the module =modules in turn are &a$kaged together in assem"lies>, and $an "e a$$essed "y a

    me$hanism $alled re#le$tion. The )ystem.;e#le$tion names&a$e $ontains $lasses that $an "e used to interrogate the

    ty&es #or a module(assem"ly.

    sing re#le$tion to a$$ess .NET metadata is very similar to using 7Ty&e:i"(7Ty&e7n#o to a$$ess ty&e li"rary data in

    !A, and it is used #or similar &ur&oses e.g. determining data ty&e sies #or marshaling data a$ross

    $onte6t(&ro$ess(ma$hine "oundaries.

    ;e#le$tion $an also "e used to dynami$ally invoke methods =see )ystem.Ty&e.7nvokeem"er > , or even $reate

    ty&es dynami$ally at runtime =see )ystem.;e#le$tion.Emit.Ty&eBuilder>.

    What is the difference 2etween Fina!i3e and 4is"ose 56ar2a&e co!!ection7 ?

    !lass instan$es o#ten en$a&sulate $ontrol over resour$es that are not managed "y the runtime, su$h as %indo%

    handles =81N>, data"ase $onne$tions, and so on. There#ore, you should &rovide "oth an e6&li$it and an im&li$it%ay to #ree those resour$es. Provide im&li$it $ontrol "y im&lementing the &rote$ted Finalie ethod on an o"9e$t

    =destru$tor synta6 in !? and the anaged E6tensions #or !DD>. The gar"age $olle$tor $alls this method at some

    &oint a#ter there are no longer any valid re#eren$es to the o"9e$t. 7n some $ases, you might %ant to &rovide

    &rogrammers using an o"9e$t %ith the a"ility to e6&li$itly release these e6ternal resour$es "e#ore the gar"age

    $olle$tor #rees the o"9e$t. 7# an e6ternal resour$e is s$ar$e or e6&ensive, "etter &er#orman$e $an "e a$hieved i# the

    &rogrammer e6&li$itly releases resour$es %hen they are no longer "eing used. To &rovide e6&li$it $ontrol,

    im&lement the is&ose method &rovided "y the 7is&osa"le 7nter#a$e. The $onsumer o# the o"9e$t should $all this

    method %hen it is done using the o"9e$t.

    is&ose $an "e $alled even i# other re#eren$es to the o"9e$t are alive. Note that even %hen you &rovide e6&li$it

    $ontrol "y %ay o# is&ose, you should &rovide im&li$it $leanu& using the Finalie method. Finalie &rovides a

    "a$ku& to &revent resour$es #rom

    &ermanently leaking i# the &rogrammer #ails to $all is&ose.What is Partia! Assem2!( $eferences?

    Full /ssem"ly re#eren$e@ / #ull assem"ly re#eren$e in$ludes the assem"ly's te6t name, version, $ulture, and &u"li$

    key token =i# the assem"ly has a strong name>. / #ull assem"ly re#eren$e is reuired i# you re#eren$e any assem"ly

    that is &art o# the $ommon language runtime or any assem"ly lo$ated in the glo"al assem"ly $a$he.

    Partial /ssem"ly re#eren$e@ 1e $an dynami$ally re#eren$e an assem"ly "y &roviding only &artial in#ormation, su$h

    as s&e$i#ying only the assem"ly name. 1hen you s&e$i#y a &artial assem"ly re#eren$e, the runtime looks #or the

    assem"ly only in the a&&li$ation dire$tory.

    1e $an make &artial re#eren$es to an assem"ly in your $ode one o# the #ollo%ing %ays@

    H se a method su$h as )ystem.;e#le$tion./ssem"ly.:oad and s&e$i#y only a &artial re#eren$e. The runtime

    $he$ks #or the assem"ly in the a&&li$ation dire$tory.

    H se the )ystem.;e#le$tion./ssem"ly.:oad1ithPartialName method and s&e$i#y only a &artial re#eren$e. Theruntime $he$ks #or the assem"ly in the a&&li$ation dire$tory and in the glo"al assem"ly $a$he

    Chan&es to which "ortion of ersion num2er indicates an incom"ati2!e chan&e?

    a9or or minor. !hanges to the ma9or or minor &ortion o# the version num"er indi$ate an in$om&ati"le $hange.

    nder this $onvention then, version 2.0.0.0 %ould "e $onsidered in$om&ati"le %ith version .0.0.0. E6am&les o# an

    in$om&ati"le $hange %ould "e a $hange to the ty&es o# some method &arameters or the removal o# a ty&e or method

    altogether. Build. The Build num"er is ty&i$ally used to distinguish "et%een daily "uilds or smaller $om&ati"le

    releases. ;evision. !hanges to the revision num"er are ty&i$ally reserved #or an in$remental "uild needed to #i6 a&arti$ular "ug. Iou'll sometimes hear this re#erred to as the emergen$y "ug #i6 num"er in that the revision is %hat

    is o#ten $hanged %hen a #i6 to a s&e$i#i$ "ug is shi&&ed to a $ustomer.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 2

  • 7/26/2019 c and Aspnet Faqs

    3/55

    C# and ASP.Net FAQ

    What is side82(8side eecution? Can two a""!ication one usin& "riate assem2!( and other usin& Shared

    assem2!( 2e stated as a side82(8side eecuta2!es?

    )ide"yside e6e$ution is the a"ility to run multi&le versions o# an a&&li$ation or $om&onent on the same $om&uter.

    Iou $an have multi&le versions o# the $ommon language runtime, and multi&le versions o# a&&li$ations and

    $om&onents that use a version o# the runtime, on the same $om&uter at the same time. )in$e versioning is only

    a&&lied to shared assem"lies, and not to &rivate assem"lies, t%o a&&li$ation one using &rivate assem"ly and one

    using shared assem"ly $annot "e stated as side"yside

    e6e$uta"les.

    Wh( strin& are ca!!ed %mmuta2!e data T("e ?

    The memory re&resentation o# string is an /rray o# !hara$ters, )o on reassigning the ne% array o# !har is #ormed

    K the start address is $hanged . Thus kee&ing the Ald string in emory #or Gar"age !olle$tor to "e dis&osed.

    What does assert57 method do?7n de"ug $om&ilation, assert takes in a Boolean $ondition as a &arameter, and sho%s the error dialog i# the $ondition

    is #alse. The &rogram &ro$eeds %ithout any interru&tion i# the $ondition is true.

    What's the difference 2etween the 4e2u& c!ass and Trace c!ass?

    o$umentation looks the same. se e"ug $lass #or de"ug "uilds, use Tra$e $lass #or "oth de"ug and release

    "uilds.

    Wh( are there fie tracin& !ee!s in S(stem.4ia&nostics.TraceSwitcher?

    The tra$ing dum&s $an "e uite ver"ose. For a&&li$ations that are $onstantly running you run the risk o#overloading the ma$hine and the hard drive. Five levels range #rom None to +er"ose, allo%ing you to #inetune the

    tra$ing a$tivities.

    Where is the out"ut of TetWriterTraceistener redirected?To the !onsole or a te6t #ile de&ending on the &arameter &assed to the $onstru$tor.

    9ow do assem2!ies find each other?

    By sear$hing dire$tory &aths. There are several #a$tors %hi$h $an a##e$t the &ath =su$h as the /&&omain host, and

    a&&li$ation $on#iguration #iles>, "ut #or &rivate assem"lies the sear$h &ath is normally the a&&li$ation's dire$tory

    and its su"dire$tories. For shared assem"lies, the sear$h &ath is normally same as the &rivate assem"ly &ath &lus

    the shared assem"ly $a$he.

    9ow does assem2!( ersionin& work?

    Ea$h assem"ly has a version num"er $alled the $om&ati"ility version. /lso ea$h re#eren$e to an assem"ly =#rom

    another assem"ly> in$ludes "oth the name and version o# the re#eren$ed assem"ly.The version num"er has #ournumeri$ &arts =e.g. ..2.LL>. /ssem"lies %ith either o# the #irst t%o &arts di##erent are normally vie%ed asin$om&ati"le. 7# the #irst t%o &arts are the same, "ut the third is di##erent, the assem"lies are deemed as 'may"e

    $om&ati"le'. 7# only the #ourth &art is di##erent, the assem"lies are deemed $om&ati"le. 8o%ever, this is 9ust the

    de#ault guideline it is the version &oli$y that de$ides to %hat e6tent these rules are en#or$ed. The version &oli$y

    $an "e s&e$i#ied via the a&&li$ation $on#iguration #ile.What is &ar2a&e co!!ection?

    Gar"age $olle$tion is a system %here"y a runtime $om&onent takes res&onsi"ility #or managing the li#etime o#

    o"9e$ts and the hea& memory that they o$$u&y. This $on$e&t is not ne% to .NET Java and many other

    languages(runtimes have used gar"age $olle$tion #or some time.

    Wh( doesn't the .NET runtime offer deterministic destruction?

    Be$ause o# the gar"age $olle$tion algorithm. The .NET gar"age $olle$tor %orks "y &eriodi$ally running through a

    list o# all the o"9e$ts that are $urrently "eing re#eren$ed "y an a&&li$ation. /ll the o"9e$ts that it doesn't #ind duringthis sear$h are ready to "e destroyed and the memory re$laimed. The im&li$ation o# this algorithm is that the

    runtime doesn't get noti#ied immediately %hen the #inal re#eren$e on an o"9e$t goes a%ay it only #inds out during

    the ne6t s%ee& o# the hea&.

    Futhermore, this ty&e o# algorithm %orks "est "y &er#orming the gar"age $olle$tion s%ee& as rarely as &ossi"le.

    Normally hea& e6haustion is the trigger #or a $olle$tion s%ee&.

    %s the !ack of deterministic destruction in .NET a "ro2!em?

    7t's $ertainly an issue that a##e$ts $om&onent design. 7# you have o"9e$ts that maintain e6&ensive or s$ar$e resour$es=e.g. data"ase lo$ks>, you need to &rovide some %ay #or the $lient to tell the o"9e$t to release the resour$e %hen it is

    done. i$roso#t re$ommend that you &rovide a method $alled is&ose=> #or this &ur&ose. 8o%ever, this $auses

    &ro"lems #or distri"uted o"9e$ts in a distri"uted system %ho $alls the is&ose=> methodM )ome #orm o# re#eren$e

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 L

  • 7/26/2019 c and Aspnet Faqs

    4/55

    C# and ASP.Net FAQ

    $ounting or o%nershi&management me$hanism is needed to handle distri"uted o"9e$ts un#ortunately the runtimeo##ers no hel& %ith this.

    What is seria!i3ation?

    )erialiation is the &ro$ess o# $onverting an o"9e$t into a stream o# "ytes. eserialiation is the o&&osite &ro$ess o#

    $reating an o"9e$t #rom a stream o# "ytes. )erialiation ( eserialiation is mostly used to trans&ort o"9e$ts =e.g.

    during remoting>, or to &ersist o"9e$ts =e.g. to a #ile or data"ase>.

    4oes the .NET Framework hae in82ui!t su""ort for seria!i3ation?

    There are t%o se&arate me$hanisms &rovided "y the .NET $lass li"rary ml)erialier and)oa&Formatter(BinaryFormatter. i$roso#t uses ml)erialier #or 1e" )ervi$es, and uses

    )oa&Formatter(BinaryFormatter #or remoting. Both are availa"le #or use in your o%n $ode.

    Can % customise the seria!i3ation "rocess?

    Ies. ml)erialier su&&orts a range o# attri"utes that $an "e used to $on#igure serialiation #or a &arti$ular $lass.

    For e6am&le, a #ield or &ro&erty $an "e marked %ith the ml7gnoreO attri"ute to e6$lude it #rom serialiation.

    /nother e6am&le is the mlElementO attri"ute, %hi$h $an "e used to s&e$i#y the : element name to "e used

    #or a &arti$ular &ro&erty or #ield.

    )erialiation via )oa&Formatter(BinaryFormatter $an also "e $ontrolled to some e6tent "y attri"utes. For e6am&le,

    the Non)erialiedO attri"ute is the euivalent o# ml)erialier's ml7gnoreO attri"ute. ltimate $ontrol o# the

    serialiation &ro$ess $an "e a$heived "y im&lementing the the 7)erialia"le inter#a$e on the $lass %hose instan$es

    are to "e serialied.Wh( is :m!Seria!i3er so s!ow?

    There is a on$e&er&ro$ess&erty&e overhead %ith ml)erialier. )o the #irst time you serialie or deserialie an

    o"9e$t o# a given ty&e in an a&&li$ation, there is a signi#i$ant delay. This normally doesn't matter, "ut it may mean,

    #or e6am&le, that ml)erialier is a &oor $hoi$e #or loading $on#iguration settings during startu& o# a G7

    a&&li$ation.

    Wh( do % &et errors when % tr( to seria!i3e a 9ashta2!e?

    ml)erialier %ill re#use to serialie instan$es o# any $lass that im&lements 7i$tionary, e.g. 8ashta"le.

    )oa&Formatter and BinaryFormatter do not have this restri$tion.

    What are attri2utes?

    There are at least t%o ty&es o# .NET attri"ute. The #irst ty&e 7 %ill re#er to as a metadata attri"ute it allo%s some

    data to "e atta$hed to a $lass or method. This data "e$omes &art o# the metadata #or the $lass, and =like other $lass

    metadata> $an "e a$$essed via re#le$tion.The other ty&e o# attri"ute is a $onte6t attri"ute. !onte6t attri"utes use a similar synta6 to metadata attri"utes "utthey are #undamentally di##erent. !onte6t attri"utes &rovide an inter$e&tion me$hanism %here"y instan$e a$tivation

    and method $alls $an "e &re and(or &ost&ro$essed.

    9ow does CAS work?

    The !/) se$urity &oli$y revolves around t%o key $on$e&ts $ode grou&s and &ermissions. Ea$h .NET assem"ly isa mem"er o# a &arti$ular $ode grou&, and ea$h $ode grou& is granted the &ermissions s&e$i#ied in a named

    &ermission set.

    For e6am&le, using the de#ault se$urity &oli$y, a $ontrol do%nloaded #rom a %e" site "elongs to the 'one 7nternet'

    $ode grou&, %hi$h adheres to the &ermissions de#ined "y the '7nternet' named &ermission set. =Naturally the

    '7nternet' named &ermission set re&resents a very restri$tive range o# &ermissions.>

    Who defines the CAS code &rou"s?

    i$roso#t de#ines some de#ault ones, "ut you $an modi#y these and even $reate your o%n. To see the $ode grou&sde#ined on your system, run '$as&ol lg' #rom the $ommandline. An my system it looks like this@

    :evel < a$hine

    !ode Grou&s@

    . /ll $ode@ Nothing

    .. one y!om&uter@ FullTrust

    ... 8onor )ki&+eri#i$ation reuests@ )ki&+eri#i$ation

    .2. one 7ntranet@ :o$al7ntranet .L. one 7nternet@ 7nternet

    .3. one ntrusted@ Nothing

    .. one Trusted@ 7nternet

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 3

  • 7/26/2019 c and Aspnet Faqs

    5/55

    C# and ASP.Net FAQ

    .-. )trongName 0023000003500000430000000-020000002300002L3L000300000L000000!F!BL24//CFE443034030LL-F40-C55-FE3-CCB!CBB3L0B/3333FEF5L35EB0-

    F4-2FL4CC-/E3!LBCB03/CFE-F34F2FC3032LEBF2!0B54-45505/!35-4!E0F!5F5LB3-E05

    0C/!E!!!C03E50C/3LLL-E305/L4L/35-2L2C2!EEEEC2F--0BC42CL5-//BF!

    /!FCL3-LL!-02F5F2@

    Note the hierar$hy o# $ode grou&s the to& o# the hierar$hy is the most general ='/ll $ode'>, %hi$h is then su"

    divided into several grou&s, ea$h o# %hi$h in turn $an "e su"divided. /lso note that =some%hat $ounterintuitively>

    a su"grou& $an "e asso$iated %ith a more &ermissive &ermission set than its &arent.9ow do % define m( own code &rou"?se $as&ol. For e6am&le, su&&ose you trust $ode #rom %%%.mydomain.$omand you %ant it have #ull a$$ess to

    your system, "ut you %ant to kee& the de#ault restri$tions #or all other internet sites. To a$hieve this, you %ould add

    a ne% $ode grou& as a su"grou& o# the 'one 7nternet' grou&, like this@

    $as&ol ag .L site %%%.mydomain.$omFullTrust

    No% i# you run $as&ol lg you %ill see that the ne% grou& has "een added as grou& .L.@

    .L. one 7nternet@ 7nternet

    .L.. )ite %%%.mydomain.$om@ FullTrust

    Note that the numeri$ la"el =.L.> is 9ust a $as&ol invention to make the $ode grou&s easy to mani&ulate #rom the

    $ommandline. The underlying runtime never sees it.9ow do % chan&e the "ermission set for a code &rou"?

    se $as&ol. 7# you are the ma$hine administrator, you $an o&erate at the 'ma$hine' level %hi$h means not only that

    the $hanges you make "e$ome the de#ault #or the ma$hine, "ut also that users $annot $hange the &ermissions to "e

    more &ermissive. 7# you are a normal =nonadmin> user you $an still modi#y the &ermissions, "ut only to make them

    more restri$tive. For e6am&le, to allo% intranet $ode to do %hat it likes you might do this@

    $as&ol $g .2 FullTrust

    Note that "e$ause this is more &ermissive than the de#ault &oli$y =on a standard system>, you should only do this at

    the ma$hine level doing it at the user level %ill have no e##e$t.

    % can't 2e 2othered with a!! this CAS stuff. Can % turn it off?

    Ies, as long as you are an administrator. Just run@ $as&ol s o##

    Can % !ook at the % for an assem2!(?

    Ies. ) su&&ly a tool $alled 7ldasm %hi$h $an "e used to vie% the metadata and 7: #or an assem"ly.Can source code 2e reerse8en&ineered from %?Ies, it is o#ten relatively straight#or%ard to regenerate highlevel sour$e =e.g. !?> #rom 7:.

    9ow can % sto" m( code 2ein& reerse8en&ineered from %?

    There is $urrently no sim&le %ay to sto& $ode "eing reverseengineered #rom 7:. 7n #uture it is likely that 7:

    o"#us$ation tools %ill "e$ome availa"le, either #rom ) or #rom third &arties. These tools %ork "y 'o&timising' the7: in su$h a %ay that reverseengineering "e$omes mu$h more di##i$ult. A# $ourse i# you are %riting %e" servi$es

    then reverseengineering is not a &ro"lem as $lients do not have a$$ess to your 7:.

    %s there 2ui!t8in su""ort for tracin&*!o&&in&?

    Ies, in the )ystem.iagnosti$s names&a$e. There are t%o main $lasses that deal %ith tra$ing e"ug and Tra$e.

    They "oth %ork in a similar %ay the di##eren$e is that tra$ing #rom the e"ug $lass only %orks in "uilds that have

    the EBG sym"ol de#ined, %hereas tra$ing #rom the Tra$e $lass only %orks in "uilds that have the T;/!E

    sym"ol de#ined. Ty&i$ally this means that you should use )ystem.iagnosti$s.Tra$e.1rite:ine #or tra$ing that you%ant to %ork in de"ug and release "uilds, and )ystem.iagnosti$s.e"ug.1rite:ine #or tra$ing that you %ant to

    %ork only in de"ug "uilds.

    Can % redirect tracin& to a fi!e?

    Ies. The e"ug and Tra$e $lasses "oth have a :isteners &ro&erty, %hi$h is a $olle$tion o# sinks that re$eive the

    tra$ing that you send via e"ug.1rite:ine and Tra$e.1rite:ine res&e$tively. By de#ault the :isteners $olle$tion

    $ontains a single sink, %hi$h is an instan$e o# the e#aultTra$e:istener $lass. This sends out&ut to the 1inL2

    Aut&ute"ug)tring=> #un$tion and also the )ystem.iagnosti$s.e"ugger.:og=> method. This is use#ul %hende"ugging, "ut i# you're trying to tra$e a &ro"lem at a $ustomer site, redire$ting the out&ut to a #ile is more

    a&&ro&riate. Fortunately, the Te6t1riterTra$e:istener $lass is &rovided #or this &ur&ose.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1

    http://www.mydomain.com/http://www.mydomain.com/http://www.mydomain.com/http://www.mydomain.com/http://www.mydomain.com/http://www.mydomain.com/http://www.mydomain.com/
  • 7/26/2019 c and Aspnet Faqs

    6/55

    C# and ASP.Net FAQ

    What are the contents of assem2!(?7n general, a stati$ assem"ly $an $onsist o# #our elements@

    T%e assembly manifest, w%ic% contains assembly metadata.

    Type metadata.

    Microsoft intermediate language &MS!"' code t%at implements t%e types.

    A set of resources.

    What is 6C 56ar2a&e Co!!ection7 and how it works?

    Ane o# the good #eatures o# the !:; is Gar"age !olle$tion, %hi$h runs in the "a$kground $olle$ting unused o"9e$tre#eren$es, #reeing us #rom having to ensure %e al%ays destroy them. 7n reality the time di##eren$e "et%een you

    releasing the o"9e$t instan$e and it "eing gar"age $olle$ted is likely to "e very small, sin$e the G! is al%ays

    running.

    Heap:

    / &ortion o# memory reserved #or a &rogram to use #or the tem&orary storage o# data stru$tures %hose e6isten$e or

    sie $annot "e determined until the &rogram is running.

    4iffernce 2etween 1ana&ed code and unmana&ed code ?

    1ana&ed Code0

    !ode that runs under a $ontra$t o# $oo&eration %ith the $ommon language runtime. anaged $ode must su&&ly

    the metadata ne$essary #or the runtime to &rovide servi$es su$h as memory management, $rosslanguage

    integration, $ode a$$ess se$urity, and automati$ li#etime $ontrol o# o"9e$ts. /ll $ode "ased on i$roso#t

    intermediate language =)7:> e6e$utes as managed $ode.

    ;n81ana&ed Code0

    !ode that is $reated %ithout regard #or the $onventions and reuirements o# the $ommon language runtime.

    nmanaged $ode e6e$utes in the $ommon language runtime environment %ith minimal servi$es =#or e6am&le, no

    gar"age $olle$tion, limited de"ugging, and so on>.

    What is 1S%< and % ?

    )7:@ =i$roso#t intermediate language>

    1hen $om&iling to managed $ode, the $om&iler translates your sour$e $ode into i$roso#t intermediate language

    =)7:>, %hi$h is a !Pinde&endent set o# instru$tions that $an "e e##i$iently $onverted to native $ode. )7:

    in$ludes instru$tions #or loading, storing, initialiing, and $alling methods on o"9e$ts, as %ell as instru$tions #or

    arithmeti$ and logi$al o&erations, $ontrol #lo%, dire$t memory a$$ess, e6$e&tion handling, and other o&erations.Be#ore $ode $an "e e6e$uted, )7: must "e $onverted to !Ps&e$i#i$ $ode, usually "y a 9ustintime =J7T>$om&iler. Be$ause the $ommon language runtime su&&lies one or more J7T $om&ilers #or ea$h $om&uter

    ar$hite$ture it su&&orts, the same set o# )7: $an "e J7T$om&iled and e6e$uted on any su&&orted ar$hite$ture.

    1hen a $om&iler &rodu$es )7:, it also &rodu$es metadata. etadata des$ri"es the ty&es in your $ode, in$luding

    the de#inition o# ea$h ty&e, the signatures o# ea$h ty&e's mem"ers, the mem"ers that your $ode re#eren$es, and otherdata that the runtime uses at e6e$ution time. The )7: and metadata are $ontained in a &orta"le e6e$uta"le =PE>

    #ile that is "ased on and e6tends the &u"lished i$roso#t PE and !ommon A"9e$t File Format =!AFF> used

    histori$ally #or e6e$uta"le $ontent. This #ile #ormat, %hi$h a$$ommodates

    )7: or native $ode as %ell as metadata, ena"les the o&erating system to re$ognie $ommon language runtime

    images. The &resen$e o# metadata in the #ile along %ith the )7: ena"les your $ode to des$ri"e itsel#, %hi$h means

    that there is no need #or ty&e li"raries or 7nter#a$e e#inition :anguage =7:>. The runtime lo$ates and e6tra$ts themetadata #rom the #ile as needed during e6e$ution.

    7:@ =7ntermediate :anguage>

    / language used as the out&ut o# a num"er o# $om&ilers and as the in&ut to a 9ustintime =J7T> $om&iler. The

    $ommon language runtime in$ludes a J7T $om&iler #or $onverting )7: to native $ode.

    What is $eference t("e and a!ue t("e ?

    ;e#eren$e Ty&e@;e#eren$e ty&es are allo$ated on the managed !:; hea&, 9ust like o"9e$t ty&es. / data ty&e that is stored as a

    re#eren$e to the value's lo$ation. The value o# a re#eren$e ty&e is the lo$ation o# the seuen$e o# "its that re&resent

    the ty&e's data. ;e#eren$e ty&es $an "e sel#des$ri"ing ty&es, &ointer ty&es, or inter#a$e ty&es

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 -

  • 7/26/2019 c and Aspnet Faqs

    7/55

    C# and ASP.Net FAQ

    +alue Ty&e@

    +alue ty&es are allo$ated on the sta$k 9ust like &rimitive ty&es in +B)$ri&t, +B- and !(!DD. +alue ty&es are not

    instantiated using ne% go out o# s$o&e %hen the #un$tion they are de#ined %ithin returns. +alue ty&es in the !:;

    are de#ined as ty&es that derive #rom system.valueTy&e.

    / data ty&e that #ully des$ri"es a value "y s&e$i#ying the seuen$e o# "its that $onstitutes the value's re&resentation.

    Ty&e in#ormation #or a value ty&e instan$e is not stored %ith the instan$e at run time, "ut it is availa"le in metadata.+alue ty&e instan$es $an "e treated as o"9e$ts using "o6ing.

    What is =oin& and un2oin& ?

    Bo6ing@

    The $onversion o# a value ty&e instan$e to an o"9e$t, %hi$h im&lies that the instan$e %ill $arry #ull ty&e in#ormation

    at run time and %ill "e allo$ated in the hea&. The i$roso#t intermediate language =)7:> instru$tion set's "o6

    instru$tion $onverts a value ty&e to an o"9e$t "y making a $o&y o# the value ty&e and em"edding it in a ne%ly

    allo$ated o"9e$t.

    nBo6ing@

    The $onversion o# an o"9e$t instan$e to a value ty&e.

    What is >%T and how is works ?

    /n a$ronym #or 9ustintime, a &hrase that des$ri"es an a$tion that is taken only %hen it "e$omes ne$essary, su$has 9ustintime $om&ilation or 9ustintime o"9e$t a$tivation

    What is "orta2!e eecuta2!e 5PE7 ?

    The #ile #ormat used #or e6e$uta"le &rograms and #or #iles to "e linked together to #orm e6e$uta"le &rograms

    What is stron& name?

    / name that $onsists o# an assem"ly's identityQits sim&le te6t name, version num"er, and $ulture in#ormation =i#

    &rovided>Qstrengthened "y a &u"li$ key and a digital signature generated over the assem"ly. Be$ause the assem"ly

    mani#est

    $ontains #ile hashes #or all the #iles that $onstitute the assem"ly im&lementation, it is su##i$ient to generate the

    digital signature over 9ust the one #ile in the assem"ly that $ontains the assem"ly mani#est. /ssem"lies %ith the

    same strong name are e6&e$ted to "e identi$al

    What is &!o2a! assem2!( cache?/ ma$hine%ide $ode $a$he that stores assem"lies s&e$i#i$ally installed to "e shared "y many a&&li$ations on the$om&uter. /&&li$ations de&loyed in the glo"al assem"ly $a$he must have a strong name.

    What is difference 2etween constants< readon!( and< static ?

    !onstants@ The value $anRt "e $hanged

    ;eadonly@ The value %ill "e initialied only on$e #rom the $onstru$tor o# the $lass.)tati$@ +alue $an "e initialied on$e.

    What is difference 2etween shared and "u2!ic?

    /n assem"ly that $an "e re#eren$ed "y more than one a&&li$ation. /n assem"ly must "e e6&li$itly "uilt to "e shared

    "y giving it a $ry&togra&hi$ally strong name.

    What is names"ace used for !oadin& assem2!ies at run time and name the methods?

    )ystem.;e#le$tion

    What are the t("es of authentication in .net?1e have three ty&es o# authenti$ation@

    . Form authenti$ation

    2. 1indo%s authenti$ation

    L. Pass&ort

    This has to "e de$lared in %e".$on#ig #ile.

    What is the difference 2etween a Struct and a C!ass ?

    The stru$t ty&e is suita"le #or re&resenting light%eight o"9e$ts su$h as Point, ;e$tangle, and !olor. /lthough it is&ossi"le to re&resent a &oint as a $lass, a stru$t is more e##i$ient in some s$enarios. For e6am&le, i# you de$lare an

    array o# 000 Point o"9e$ts,

    you %ill allo$ate additional memory #or re#eren$ing ea$h o"9e$t. 7n this $ase, the stru$t is less e6&ensive.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 C

  • 7/26/2019 c and Aspnet Faqs

    8/55

    C# and ASP.Net FAQ

    1hen you $reate a stru$t o"9e$t using the ne% o&erator, it gets $reated and the a&&ro&riate $onstru$tor is $alled.nlike $lasses, stru$ts $an "e instantiated %ithout using the ne% o&erator. 7# you do not use ne%, the #ields %ill

    remain unassigned and the o"9e$t $annot "e used until all o# the #ields are initialied. 7t is an error to de$lare a

    de#ault =&arameterless> $onstru$tor #or a stru$t. / de#ault $onstru$tor is al%ays &rovided to initialie the stru$t

    mem"ers to their de#ault values. 7t is an error to initialie an instan$e #ield in a stru$t.

    There is no inheritan$e #or stru$ts as there is #or $lasses. / stru$t $annot inherit #rom another stru$t or $lass, and it

    $annot "e the "ase o# a $lass. )tru$ts, ho%ever, inherit #rom the "ase $lass A"9e$t. / stru$t $an im&lement

    inter#a$es, and it does that e6a$tly as $lasses do./ stru$t is a value ty&e, %hile a $lass is a re#eren$e ty&e.

    9ow 2i& is the datat("e int in .NET?

    L2 "its.

    9ow 2i& is the char?

    - "its =ni$ode>.

    9ow do (ou initiate a strin& without esca"in& each 2acks!ash?

    Put an S sign in #ront o# the dou"leuoted string.

    What's the access !ee! of the isi2i!it( t("e interna!?

    !urrent a&&li$ation.

    E"!ain enca"su!ation ?

    The im&lementation is hidden, the inter#a$e is e6&osed.

    What data t("e shou!d (ou use if (ou want an 82it a!ue that's si&ned?s"yte.

    S"eakin& of =oo!ean data t("es< what's different 2etween C# and C*C@@?

    There's no $onversion "et%een 0 and #alse, as %ell as any other num"er and true, like in !(!DD.

    Where are the a!ue8t("e aria2!es a!!ocated in the com"uter $A1?

    )ta$k.

    Where do the reference8t("e aria2!es &o in the $A1?

    The re#eren$es go on the sta$k, %hile the o"9e$ts themselves go on the hea&.

    What is the difference 2etween the a!ue8t("e aria2!es and reference8t("e aria2!es in terms of &ar2a&e

    co!!ection?

    The valuety&e varia"les are not gar"age$olle$ted, they 9ust #all o## the sta$k %hen they #all out o# s$o&e, the

    re#eren$ety&e o"9e$tsare &i$ked u& "y G! %hen their re#eren$es go null.

    9ow do (ou conert a strin& into an inte&er in .NET?

    7ntL2.Parse=string>

    9ow do (ou 2o a "rimitie data t("e aria2!e?

    /ssign it to the o"9e$t, &ass an o"9e$t.

    Wh( do (ou need to 2o a "rimitie aria2!e?

    To &ass it "y re#eren$e.

    What's the difference 2etween >aa and .NET &ar2a&e co!!ectors?

    )un le#t the im&lementation o# a s&e$i#i$ gar"age $olle$tor u& to the J;E develo&er, so their &er#orman$e varies

    %idely, de&ending on %hose J;E you're using. i$roso#t standardied on their gar"age $olle$tion.

    9ow do (ou enforce &ar2a&e co!!ection in .NET?

    )ystem.G!.!olle$t=>What's different a2out names"ace dec!aration when com"arin& that to "acka&e dec!aration in >aa?

    No semi$olon.

    What's the difference 2etween const and readon!(?

    Iou $an initialie readonly varia"les to some runtime values. :et's say your &rogram uses $urrent date and time as

    one o# the values that %on't $hange. This %ay you de$lare &u"li$ readonly string ateT < ne%

    ateTime=>.To)tring=>.

    What ha""ens when (ou encounter a continue statement inside the for !oo"?

    The $ode #or the rest o# the loo& is ignored, the $ontrol is trans#erred "a$k to the "eginning o# the loo&.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 5

  • 7/26/2019 c and Aspnet Faqs

    9/55

    C# and ASP.Net FAQ

    What's the adanta&e of usin& S(stem.Tet.Strin&=ui!der oer S(stem.Strin&?)tringBuilder is more e##i$ient in the $ases, %here a lot o# mani&ulation is done to the te6t. )trings are immuta"le,

    so ea$h time it's "eing o&erated on, a ne% instan$e is $reated.

    Can (ou store mu!ti"!e data t("es in S(stem.Arra(?

    No.

    What's the difference 2etween the S(stem.Arra(.Co"(To57 and S(stem.Arra(.C!one57?

    The #irst one &er#orms a dee& $o&y o# the array, the se$ond one is shallo%.

    9ow can (ou sort the e!ements of the arra( in descendin& order?By $alling )ort=> and then ;everse=> methods.

    What's the .NET datat("e that a!!ows the retriea! of data 2( a uniue ke(?

    8ashTa"le.

    What's c!ass Sortedist underneath?

    / sorted 8ashTa"le.

    Wi!! fina!!( 2!ock &et eecuted if the ece"tion had not occurred?

    Ies.

    Can mu!ti"!e catch 2!ocks 2e eecuted?

    No, on$e the &ro&er $at$h $ode #ires o##, the $ontrol is trans#erred to the #inally "lo$k =i# there are any>, and then

    %hatever #ollo%s the #inally "lo$k.

    Wh( is it a 2ad idea to throw (our own ece"tions?

    1ell, i# at that &oint you kno% that an error has o$$urred, then %hy not %rite the &ro&er $ode to handle that errorinstead o# &assing a ne% E6$e&tion o"9e$t to the $at$h "lo$kM Thro%ing your o%n e6$e&tions signi#ies some design

    #la%s in the &ro9e$t.

    What's a de!e&ate?

    / delegate o"9e$t en$a&sulates a re#eren$e to a method. 7n !DD they %ere re#erred to as #un$tion &ointers.

    What's a mu!ticast de!e&ate?

    7t's a delegate that &oints to and eventually #ires o## several methods.

    9ow's the 4 9e!! "ro2!em so!ed in .NET?

    /ssem"ly versioning allo%s the a&&li$ation to s&e$i#y not only the li"rary it needs to run =%hi$h %as availa"le

    under 1inL2>, "ut also the version o# the assem"ly.

    What are the wa(s to de"!o( an assem2!(?

    /n )7 installer, a !/B ar$hive, and !API $ommand.What's a sate!!ite assem2!(?

    1hen you %rite a multilingual or multi$ultural a&&li$ation in .NET, and %ant to distri"ute the $ore a&&li$ation

    se&arately #rom the lo$alied modules, the lo$alied assem"lies that modi#y the $ore a&&li$ation are $alled satellite

    assem"lies.

    What names"aces are necessar( to create a !oca!i3ed a""!ication?

    )ystem.Glo"aliation, )ystem.;esour$es.

    What does assert57 do?

    7n de"ug $om&ilation, assert takes in a Boolean $ondition as a &arameter, and sho%s the error dialog i# the $ondition

    is #alse. The &rogram &ro$eeds %ithout any interru&tion i# the $ondition is true.

    What's the difference 2etween the 4e2u& c!ass and Trace c!ass?

    o$umentation looks the same. se e"ug $lass #or de"ug "uilds, use Tra$e $lass #or "oth de"ug and release

    "uilds.Wh( are there fie tracin& !ee!s in S(stem.4ia&nostics.TraceSwitcher?

    The tra$ing dum&s $an "e uite ver"ose and #or some a&&li$ations that are $onstantly running you run the risk o#

    overloading the ma$hine and the hard drive there. Five levels range #rom None to +er"ose, allo%ing to #inetune the

    tra$ing a$tivities.

    Where is the out"ut of TetWriterTraceistener redirected?

    To the !onsole or a te6t #ile de&ending on the &arameter &assed to the $onstru$tor.

    What names"aces are necessar( to create a !oca!i3ed a""!ication?

    )ystem.Glo"aliation, )ystem.;esour$es.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 4

  • 7/26/2019 c and Aspnet Faqs

    10/55

    C# and ASP.Net FAQ

    What are three test cases (ou shou!d &o throu&h in unit testin&?

    Positive test $ases =$orre$t data, $orre$t out&ut>, negative test $ases ="roken or missing data, &ro&er handling>,

    e6$e&tion test $ases =e6$e&tions are thro%n and $aught &ro&erly>.

    Can (ou chan&e the a!ue of a aria2!e whi!e de2u&&in& a C# a""!ication?

    Ies, i# you are de"ugging via +isual )tudio.NET, 9ust go to 7mmediate %indo%.

    What's the im"!icit name of the "arameter that &ets "assed into the c!ass' set method?

    +alue, and it's dataty&e de&ends on %hatever varia"le %e're $hanging.

    9ow do (ou inherit from a c!ass in C#?Pla$e a $olon and then the name o# the "ase $lass. Noti$e that it's dou"le $olon in !DD.

    4oes C# su""ort mu!ti"!e inheritance?

    No, use inter#a$es instead.

    When (ou inherit a "rotected c!ass8!ee! aria2!e< who is it aai!a2!e to?

    erived !lasses.

    What's the to" .NET c!ass that eer(thin& is deried from?

    )ystem.A"9e$t.

    9ow's method oerridin& different from oer!oadin&?

    1hen overriding, you $hange the method "ehavior #or a derived $lass. Averloading sim&ly involves having a

    method %ith the same name %ithin the $lass.

    What does the ke(word irtua! mean in the method definition?

    The method $an "e overridden.Can (ou dec!are the oerride method static whi!e the ori&ina! method is non8static?

    No, you $an't, the signature o# the virtual method must remain the same, only the key%ord virtual is $hanged to

    key%ord override.

    Can (ou oerride "riate irtua! methods?

    No, moreover, you $annot a$$ess &rivate methods in inherited $lasses, have to "e &rote$ted in the "ase $lass to

    allo% any sort o# a$$ess.

    Can (ou "reent (our c!ass from 2ein& inherited and 2ecomin& a 2ase c!ass for some other c!asses?

    Ies, that's %hat key%ord sealed in the $lass de#inition is #or. The develo&er trying to derive #rom your $lass %ill get

    a message@ $annot inherit #rom )ealed $lass 1hateverBase!lassName. 7t's the same $on$e&t as #inal $lass in Java.

    Can (ou a!!ow c!ass to 2e inherited< 2ut "reent the method from 2ein& oer8ridden?

    Ies, 9ust leave the $lass &u"li$ and make the method sealed.Wh( can't (ou s"ecif( the accessi2i!it( modifier for methods inside the interface?

    They all must "e &u"li$. There#ore, to &revent you #rom getting the #alse im&ression that you have any #reedom o#

    $hoi$e, you are not allo%ed to s&e$i#y any a$$essi"ility, it's &u"li$ "y de#ault.

    Can (ou inherit mu!ti"!e interfaces?

    Ies, %hy not.

    And if the( hae conf!ictin& method names?

    7t's u& to you to im&lement the method inside your o%n $lass, so im&lementation is le#t entirely u& to you. This

    might $ause a &ro"lem on a higherlevel s$ale i# similarly named methods #rom di##erent inter#a$es e6&e$t di##erent

    data, "ut as #ar as $om&iler $ares you're okay.

    What's the difference 2etween an interface and a2stract c!ass?

    7n the inter#a$e all methods must "e a"stra$t, in the a"stra$t $lass some methods $an "e $on$rete. 7n the inter#a$e no

    a$$essi"ility modi#iers are allo%ed, %hi$h is ok in a"stra$t $lasses.9ow can (ou oer!oad a method?

    i##erent &arameter data ty&es, di##erent num"er o# &arameters, di##erent order o# &arameters.

    %f a 2ase c!ass has a 2unch of oer!oaded constructors< and an inherited c!ass has another 2unch of

    oer!oaded constructors< can (ou enforce a ca!! from an inherited constructor to an ar2itrar( 2ase

    constructor?

    Ies, 9ust &la$e a $olon, and then key%ord "ase =&arameter list to invoke the a&&ro&riate $onstru$tor> in the

    overloaded $onstru$tor de#inition inside the inherited $lass.

    What's the difference 2etween S(stem.Strin& and S(stem.Strin&=ui!der c!asses?

    )ystem.)tring is immuta"le, )ystem.)tringBuilder %as designed %ith the &ur&ose o# having a muta"le string %here

    a variety o# o&erations $an "e &er#ormed.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 0

  • 7/26/2019 c and Aspnet Faqs

    11/55

    C# and ASP.Net FAQ

    4oes C# su""ort mu!ti"!e8inheritance?

    No, use inter#a$es instead.

    When (ou inherit a "rotected c!ass8!ee! aria2!e< who is it aai!a2!e to?

    The derived $lass.

    Are "riate c!ass8!ee! aria2!es inherited?

    Ies, "ut they are not a$$essi"le. /lthough they are not visi"le or a$$essi"le via the $lass inter#a$e, they are

    inherited.

    4escri2e the accessi2i!it( modifier B"rotected interna!B.7t is availa"le to derived $lasses and $lasses %ithin the same /ssem"ly =and naturally #rom the "ase $lass it's

    de$lared in>.

    What's the to" .NET c!ass that eer(thin& is deried from?

    )ystem.A"9e$t.

    What's the adanta&e of usin& S(stem.Tet.Strin&=ui!der oer S(stem.Strin&?

    )tringBuilder is more e##i$ient in $ases %here there is a large amount o# string mani&ulation. )trings are

    immuta"le, so ea$h time it's "eing o&erated on, a ne% instan$e is $reated.

    Can (ou store mu!ti"!e data t("es in S(stem.Arra(?

    No.

    What's the .NET c!ass that a!!ows the retriea! of a data e!ement usin& a uniue ke(?

    8ashTa"le.

    Wi!! the fina!!( 2!ock &et eecuted if an ece"tion has not occurred?Ies.

    What's an a2stract c!ass?

    / $lass that $annot "e instantiated. /n a"stra$t $lass is a $lass that must "e inherited and have the methods

    overridden. /n a"stra$t $lass is essentially a "lue&rint #or a $lass %ithout any im&lementation.

    When do (ou a2so!ute!( hae to dec!are a c!ass as a2stract?

    . 1hen at least one o# the methods in the $lass is a"stra$t.

    2. 1hen the $lass itsel# is inherited #rom an a"stra$t $lass, "ut not all "ase a"stra$t methods have "een

    overridden.

    What's an interface?7t's an a"stra$t $lass %ith &u"li$ a"stra$t methods all o# %hi$h must "e im&lemented in the inherited $lasses.

    Wh( can't (ou s"ecif( the accessi2i!it( modifier for methods inside the interface?

    They all must "e &u"li$. There#ore, to &revent you #rom getting the #alse im&ression that you have any #reedom o#

    $hoi$e,you are not allo%ed to s&e$i#y any a$$essi"ility, it's &u"li$ "y de#ault.

    What's the difference 2etween an interface and a2stract c!ass?

    7n an inter#a$e $lass, all methods must "e a"stra$t. 7n an a"stra$t $lass some methods $an "e $on$rete. 7n an

    inter#a$e $lass, no a$$essi"ility modi#iers are allo%ed, %hi$h is ok in an a"stra$t $lass.

    9ow is method oerridin& different from method oer!oadin&?1hen overriding a method, you $hange the "ehavior o# the method #or the derived $lass. Averloading a method

    sim&ly involves

    having another method %ith the same name %ithin the $lass.

    Can (ou dec!are an oerride method to 2e static if the ori&ina! method is non8static?

    No. The signature o# the virtual method must remain the same, only the key%ord virtual is $hanged to key%ord

    override.

    Can (ou oerride "riate irtua! methods?

    No. Private methods are not a$$essi"le outside the $lass.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1

  • 7/26/2019 c and Aspnet Faqs

    12/55

    C# and ASP.Net FAQ

    Can (ou write a c!ass without s"ecif(in& names"ace? Which names"ace does it 2e!on& to 2( defau!t?

    Ies, you $an, then the $lass "elongs to glo"al names&a$e %hi$h has no name. For $ommer$ial &rodu$ts, naturally,

    you %ouldn't %ant glo"al names&a$e.

    What is a formatter?

    / #ormatter is an o"9e$t that is res&onsi"le #or en$oding and serialiing data into messages on one end, and

    deserialiing and de$oding messages into data on the other end.

    4ifferent 2*w .NET >-EE ?i##eren$es "et%een J2EE and the .NET Plat#orm

    Vendor Neutrality

    The .NET &lat#orm is not vendor neutral, it is tied to the i$roso#t o&erating systems. But neither are any o# the

    J2EE im&lementations

    any $om&anies "uy into J2EE "elieving that it %ill give them vendor neutrality. /nd, in #a$t, this is a stated goal

    o# )un's vision@

    Overall Maturity

    Given that the .NET &lat#orm has a three year lead over J2EE, it should "e no sur&rise to learn that the .NET

    &lat#orm is #ar more mature than the J2EE &lat#orm. 1hereas %e have high volume highly relia"le %e" sites

    using .NET te$hnologies =N/)/U and ell "eing among many e6am&les>

    Interoperability and Web Services

    The .NET &lat#orm e!olla"oration model is, as 7 have dis$ussed at length, "ased on the 7 and )A/P standards.These standards are %idely su&&orted "y more than 00 $om&anies. i$roso#t, along %ith 7B and /ri"a, are the

    leaders in this area. )un is a mem"er o# the 7 $onsortium and re$ognies the im&ortan$e o# the 7

    standards. 7n a re$ent &ress release, )un's George Paolini, +i$e President #or the Java !ommunity evelo&ment,

    says@

    )un has al%ays %orked to hel& esta"lish and su&&ort o&en, standards"ased te$hnologies that #a$ilitate the gro%th

    o# net%ork"ased a&&li$ations, and %e see 7 as an im&ortant &ro9e$t to esta"lish a registry #rame%ork #or

    "usinessto"usiness e$ommer$e

    But %hile )un &u"li$ly says it "elieves in the 7 standards, in reality, )un has done nothing %hatsoever to

    in$or&orate any o# the 7 standards into J2EE.

    Framework Support

    The .NET &lat#orm in$ludes su$h an e!ommer$e #rame%ork $alled !ommer$e )erver. /t this &oint, there is noeuivalent vendorneutral #rame%ork in the J2EE s&a$e. 1ith J2EE, you should assume that you %ill "e "uildingyour ne% e!ommer$e solution #rom s$rat$h

    oreover, no matter %hat J2EEO vendor you $hoose, i# you e6&e$t a $om&onent #rame%ork that %ill allo% you to

    ui$kly #ield $om&lete e"usiness a&&li$ations, you are in #or a #rustrating e6&erien$e

    Lanuae

    7n the language arena, the $hoi$e is a"out as sim&le as it gets. J2EE su&&orts Java, and only Java. 7t %ill not su&&ort

    any other language in the #oreseea"le #uture. The .NET &lat#orm su&&orts every language e6$e&t Java =although it

    does su&&ort a language that is synta$ti$ally and #un$tionally euivalent to Java, !?>. 7n #a$t, given the im&ortan$e

    o# the .NET &lat#orm as a language inde&endent vehi$le, it is likely that any language that $omes out in the near

    #uture %ill in$lude su&&ort #or the .NET &lat#orm.

    )ome $om&anies are under the im&ression that J2EE su&&orts other languages. /lthough "oth 7B's 1e")&here

    and BE/'s 1e":ogi$ su&&ort other languages, neither does it through their J2EE te$hnology. There are only t%oo##i$ial %ays in the J2EE &lat#orm to a$$ess other languages, one through the Java Native 7nter#a$e and the other

    through !A;B/ intero&era"ility. )un re$ommends the later a&&roa$h. /s )un's istinguished )$ientist and Java

    /r$hite$t ;i$k !attell said in a re$ent intervie%.

    !ortability

    The reason that o&erating system &orta"ility is a &ossi"ility %ith J2EE is not so mu$h "e$ause o# any inherent

    &orta"ility o# J2EE, as it is that most o# the J2EE vendors su&&ort multi&le o&erating systems. There#ore as long as

    one sti$ks %ith a given J2EE vendor and a given data"ase vendor, moving #rom one o&erating system to anothershould "e &ossi"le. This is &ro"a"ly the single most im&ortant "ene#it in #avor o# J2EE over the .NET &lat#orm,

    %hi$h is limited to the 1indo%s o&erating system. 7t is %orth noting, ho%ever, that i$roso#t has su"mitted the

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 2

  • 7/26/2019 c and Aspnet Faqs

    13/55

    C# and ASP.Net FAQ

    s&e$i#i$ations #or !? and a su"set o# the .NET Frame%ork =$alled the $ommon language in#rastru$ture> to E!/,the grou& that standardies Java)$ri&t.

    J2EE o##ers an a$$e&ta"le solution to 7)+s %hen the &rodu$t must "e marketed to non1indo%s $ustomers,

    &arti$ularly %hen the J2EE &lat#orm itsel# $an "e "undled %ith the 7)+'s &rodu$t as an integrated o##ering.

    7# the &rimary $ustomer "ase #or the 7)+ is 1indo%s $ustomers, then the .NET &lat#orm should "e $hosen. 7t %ill

    &rovide mu$h "etter &er#orman$e at a mu$h lo%er $ost.

    "lient device independenceThe ma9or di##eren$e "eing that %ith Java, it is the &resentation tier &rogrammer that determines the ultimate

    8T: that %ill "e delivered to the $lient, and %ith .NET, it is a +isual )tudio.NET $ontrol.

    This Java a&&roa$h has three &ro"lems. First, it reuires a lot o# $ode on the &resentation tier, sin$e every &ossi"le

    thin $lient system reuires a di##erent $ode &ath. )e$ond, it is very di##i$ult to test the $ode %ith every &ossi"le thin

    $lient system. Third, it is very di##i$ult to add ne% thin $lients to an e6isting a&&li$ation, sin$e to do so involves

    sear$hing through, and modi#ying a tremendous amount o# &resentation tier logi$.

    The .NET Frame%ork a&&roa$h is to %rite devi$e inde&endent $ode that intera$ts %ith visual $ontrols. 7t is the

    $ontrol, not the &rogrammer, that is res&onsi"le #or determining %hat 8T: to deliver, "ased on the $a&a"ilities o#

    the $lient devi$e.. 7n the .NET Frame%ork model, one $an #orget that su$h a thing as 8T: even e6istsV Contd ....

    What are the 1ain Features of .NET "!atform?

    Features o# .NET Plat#orm are @

    Common an&ua&e $untimeE6&lains the #eatures and "ene#its o# the $ommon language runtime, a runtime environment that manages the

    e6e$ution o# $ode and &rovides servi$es that sim&li#y the develo&ment &ro$ess.

    Assem2!ies

    e#ines the $on$e&t o# assem"lies, %hi$h are $olle$tions o# ty&es and resour$es that #orm logi$al units o#

    #un$tionality. /ssem"lies are the #undamental units o# de&loyment, version $ontrol, reuse, a$tivation s$o&ing, and

    se$urity &ermissions. /&&li$ation omains

    E6&lains ho% to use a&&li$ation domains to &rovide isolation "et%een a&&li$ations.

    $untime 9osts

    es$ri"es the runtime hosts su&&orted "y the .NET Frame%ork, in$luding /)P.NET, 7nternet E6&lorer, and shell

    e6e$uta"les.

    Common T("e S(stem

    7denti#ies the ty&es su&&orted "y the $ommon language runtime.etadata and )el#es$ri"ing !om&onentsE6&lains ho% the .NET Frame%ork sim&li#ies $om&onent intero&eration "y allo%ing $om&ilers to emit additional

    de$larative in#ormation, or metadata, into all modules and assem"lies.

    !ross:anguage 7ntero&era"ility

    E6&lains ho% managed o"9e$ts $reated in di##erent &rogramming languages $an intera$t %ith one another.

    .NET Framework Securit(

    es$ri"es me$hanisms #or &rote$ting resour$es and $ode #rom unauthoried $ode and unauthoried users.

    .NET Framework C!ass i2rar(

    7ntrodu$es the li"rary o# ty&es &rovided "y the .NET Frame%ork, %hi$h e6&edites and o&timies the develo&ment

    &ro$ess and gives you a$$ess to system #un$tionality.

    What is the use of >%T ?

    J7T =Just 7n Time> is a $om&iler %hi$h $onverts )7: $ode to Native !ode =ie.. !Ps&e$i#i$ $ode that runs onthe same $om&uter ar$hite$ture>.

    Be$ause the $ommon language runtime su&&lies a J7T $om&iler #or ea$h su&&orted !P ar$hite$ture, develo&ers

    $an %rite a set o# )7: that $an "e J7T$om&iled and run on $om&uters %ith di##erent ar$hite$tures. 8o%ever, your

    managed $ode %ill run only on a s&e$i#i$ o&erating system i# it $alls &lat#orms&e$i#i$ native /P7s, or a &lat#orm

    s&e$i#i$ $lass li"rary.

    J7T $om&ilation takes into a$$ount the #a$t that some $ode might never get $alled during e6e$ution. ;ather than

    using time and memory to $onvert all the )7: in a &orta"le e6e$uta"le =PE> #ile to native $ode, it $onverts the)7: as needed during e6e$ution and stores the resulting native $ode so that it is a$$essi"le #or su"seuent $alls.

    The loader $reates and atta$hes a stu" to ea$h o# a ty&e's methods %hen the ty&e is loaded. An the initial $all to the

    method, the stu" &asses $ontrol to the J7T $om&iler, %hi$h $onverts the )7: #or that method into native $ode and

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 L

  • 7/26/2019 c and Aspnet Faqs

    14/55

    C# and ASP.Net FAQ

    modi#ies the stu" to dire$t e6e$ution to the lo$ation o# the native $ode. )u"seuent $alls o# the J7T$om&iledmethod &ro$eed dire$tly to the native $ode that %as &reviously generated, redu$ing the time it takes to J7T$om&ile

    and run the $ode.

    What meant of assem2!( &!o2a! assem2!( cache 5&ac7 1eta data.

    /ssem"ly @ /n assem"ly is the &rimary "uilding "lo$k o# a .NET "ased a&&li$ation. 7t is a $olle$tion o#

    #un$tionality that is "uilt, versioned, and de&loyed as a single im&lementation unit =as one or more #iles>. /ll

    managed ty&es and resour$es are marked either as a$$essi"le only %ithin their im&lementation unit, or as a$$essi"le

    "y $ode outside that unit. 7t over$omes the &ro"lem o# 'dll 8ell'.The .NET Frame%ork uses assem"lies as the#undamental unit #or several &ur&oses@

    )e$urity

    Ty&e 7dentity

    ;e#eren$e )$o&e

    +ersioning

    e&loyment

    Glo"al /ssem"ly !a$he @ /ssem"lies $an "e shared among multi&le a&&li$ations on the ma$hine "y registering

    them in glo"al /ssem"ly $a$he=G/!>. G/! is a ma$hine %ide a lo$al $a$he o# assem"lies maintained "y the .NET

    Frame%ork. 1e $an register the assem"ly to glo"al assem"ly $a$he "y using ga$util $ommand.

    1e $an Navigate to the G/! dire$tory, !@W%inntW/ssem"ly in e6&lore. 7n the tools menu sele$t the $a$he&ro&erties in the %indo%s dis&layed you $an set the memory limit in B used "y the G/!

    etaata @/ssem"lies have ani#ests. This ani#est $ontains etadata in#ormation o# the odule(/ssem"ly as%ell as it $ontains detailed etadata o# other assem"lies(modules re#eren$es =e6&orted>. 7t's the /ssem"ly ani#est

    %hi$h di##erentiates "et%een an /ssem"ly and a odule.

    What are the mo2i!e deices su""orted 2( .net "!atform

    The i$roso#t .NET !om&a$t Frame%ork is designed to run on mo"ile devi$es su$h as mo"ile &hones, Personal

    igital /ssistants =P/s>, and em"edded devi$es. The easiest %ay to develo& and test a )mart evi$e /&&li$ation

    is to use an emulator.

    These devi$es are divided into t%o main divisions@

    > Those that are dire$tly su&&orted "y .NET =Po$ket P!s, iode &hones, and 1/P devi$es>

    2> Those that are not =Palm A) and J2E&o%ered devi$es>.

    What is 6;%4 < wh( we use it and where?

    G7 @ G7 is )hort #orm o# Glo"ally niue 7denti#ier, a uniue 25"it num"er that is &rodu$ed "y the

    1indo%s A) or "y some 1indo%s a&&li$ations to identi#y a &arti$ular $om&onent, a&&li$ation, #ile, data"ase entry,and(or user. For instan$e, a 1e" site may generate a G7 and assign it to a user's "ro%ser to re$ord and tra$k the

    session. / G7 is also used in a 1indo%s registry to identi#y !A ::s. *no%ing %here to look in the registry

    and having the $orre$t G7 yields a lot in#ormation a"out a !A o"9e$t =i.e., in#ormation in the ty&e li"rary, its

    &hysi$al lo$ation, et$.>. 1indo%s also identi#ies user a$$ounts "y a username =$om&uter(domain and username> andassigns it a G7. )ome data"ase administrators even %ill use G7s as &rimary key values in data"ases.

    G7s $an "e $reated in a num"er o# %ays, "ut usually they are a $om"ination o# a #e% uniue settings "ased on

    s&e$i#i$ &oint in time =e.g., an 7P address, net%ork /! address, $lo$k date(time, et$.>.

    4escri2e the difference 2etween in!ine and code 2ehind 8 which is 2est in a !oose!( cou"!ed so!ution

    /)P.NET su&&orts t%o modes o# &age develo&ment@ Page logi$ $ode that is %ritten inside runat is a translation used as the out&ut o# a num"er o# $om&ilers. 7t is the in&ut

    to a 9ustintime =J7T> $om&iler. The !ommon :anguage ;untime in$ludes a J7T $om&iler #or the $onversion o#

    )7: to native $ode.

    Be#ore i$roso#t 7ntermediate :anguage =)7:> $an "e e6e$uted it, must "e $onverted "y the .NET Frame%ork

    9ustintime =J7T> $om&iler to native $ode. This is !Ps&e$i#i$ $ode that runs on the same $om&uter ar$hite$ture as

    the J7T $om&iler. ;ather than using time and memory to $onvert all o# the )7: in a &orta"le e6e$uta"le =PE> #ile

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 3

  • 7/26/2019 c and Aspnet Faqs

    15/55

    C# and ASP.Net FAQ

    to native $ode. 7t $onverts the )7: as needed %hilst e6e$uting, then $a$hes the resulting native $ode so itsa$$essi"le #or any su"seuent $alls.

    9ow man( .NET !an&ua&es can a sin&!e .NET 4 contain?

    Ane

    What t("e of code 5serer or c!ient7 is found in a Code8=ehind c!ass?

    )erver

    Whats an assem2!(?

    /ssem"lies are the "uilding "lo$ks o# .NET Frame%ork a&&li$ations they #orm the #undamental unit o#de&loyment, version $ontrol, reuse, a$tivation s$o&ing, and se$urity &ermissions. /n assem"ly is a $olle$tion o#

    ty&es and resour$es that are "uilt to %ork together and #orm a logi$al unit o# #un$tionality. /n assem"ly &rovides

    the $ommon language runtime %ith the in#ormation it needs to "e a%are o# ty&e im&lementations. To the runtime, a

    ty&e does not e6ist outside the $onte6t o# an assem"ly.

    9ow man( c!asses can a sin&!e .NET 4 contain?

    nlimited.

    What is the difference 2etween strin& and Strin& ?

    No di##eren$e

    What is manifest?

    7t is the metadata that des$ri"es the assem"lies.

    What is metadata?

    etadata is ma$hinereada"le in#ormation a"out a resour$e, or data a"out data. )u$h in#ormation might in$ludedetails on $ontent, #ormat, sie, or other $hara$teristi$s o# a data

    sour$e. 7n .NET, metadata in$ludes ty&e de#initions, version in#ormation, e6ternal assem"ly re#eren$es, and other

    standardied in#ormation.

    What are the t("es of assem2!ies?

    There are #our ty&es o# assem"lies in .NET@

    )tati$ assem"lies

    These are the .NET PE #iles that you $reate at $om&ile time.

    ynami$ assem"lies

    These are PE#ormatted, inmemory assem"lies that you dynami$ally $reate at runtime using the $lasses in the

    )ystem.;e#le$tion.Emit names&a$e.

    Private assem"lies

    These are stati$ assem"lies used "y a s&e$i#i$ a&&li$ation.Pu"li$ or shared assem"liesThese are stati$ assem"lies that must have a uniue shared name and $an "e used "y any a&&li$ation.

    /n a&&li$ation uses a &rivate assem"ly "y re#erring to the assem"ly using a stati$ &ath or through an :"ased

    a&&li$ation $on#iguration #ile. 1hile the !:; doesn't en#or$e versioning &oli$ies$he$king %hether the $orre$t

    version is used#or &rivate assem"lies, it ensures that ana&&li$ation uses the $orre$t shared assem"lies %ith %hi$h the a&&li$ation %as "uilt. Thus, an a&&li$ation uses a

    s&e$i#i$ shared assem"ly "y re#erring to the s&e$i#i$ shared assem"ly, and the !:; ensures that the $orre$t version

    is loaded at runtime.

    7n .NET, an assem"ly is the smallest unit to %hi$h you $an asso$iate a version num"er

    What are de!e&ates? where are the( used ?

    / delegate de#ines a re#eren$e ty&e that $an "e used to en$a&sulate a method %ith a s&e$i#i$ signature. / delegate

    instan$e en$a&sulates a stati$ or an instan$e method. elegates are roughly similar to #un$tion &ointers in !DDho%ever, delegates are ty&esa#e and se$ure.

    When do (ou use iruta! ke(word?.

    1hen %e need to override a method o# the "ase $lass in the su" $lass, then %e give the virtual key%ord in the "ase

    $lass method. This makes the method in the "ase $lass to "e overrida"le. ethods, &ro&erties, and inde6ers $an "e

    virtual, %hi$h means that their im&lementation $an "e overridden in derived $lasses.

    What are c!ass access modifiers ?

    /$$ess modi#iers are key%ords used to s&e$i#y the de$lared a$$essi"ility o# a mem"er or a ty&e. This se$tionintrodu$es the #our a$$ess modi#iers@

    X Pu"li$ /$$ess is not restri$ted.

    X Prote$ted /$$ess is limited to the $ontaining $lass or ty&es derived #rom the $ontaining $lass.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1

  • 7/26/2019 c and Aspnet Faqs

    16/55

    C# and ASP.Net FAQ

    X 7nternal /$$ess is limited to the $urrent assem"ly.X Prote$ted inertnal /$$ess is limited to the $urrent assem"ly or ty&es derived X #rom the $ontaining $lass.

    X Private /$$ess is limited to the $ontaining ty&e.

    What %s =oin& And ;n2oin&?

    Bo6ing @ Bo6ing is an im&li$it $onversion o# a value ty&e to the ty&e o"9e$t ty&e

    Eg@

    !onsider the #ollo%ing de$laration o# a valuety&e varia"le@

    int i < 2Lo"9e$t o < =o"9e$t> i

    Bo6ing !onversion

    nBo6ing @ n"o6ing is an e6&li$it $onversion #rom the ty&e o"9e$t to a value ty&e

    Eg@

    int i < 2L (( / value ty&e

    o"9e$t "o6 < i (( Bo6ing

    int 9 < =int>"o6 (( n"o6ing

    What is Da!ue t("e and refernce t("e in .Net?.

    +alue Ty&e @ / varia"le o# a value ty&e al%ays $ontains a value o# that ty&e. The assignment to a varia"le o# a value

    ty&e $reates a $o&y o# the assigned value, %hile the assignment to a varia"le o# a re#eren$e ty&e $reates a $o&y o#

    the re#eren$e "ut not o# the re#eren$ed o"9e$t.

    The value ty&es $onsist o# t%o main $ategories@Y )tu$t Ty&e

    Y Enumeration Ty&e

    ;e#eren$e Ty&e @+aria"les o# re#eren$e ty&es, re#erred to as o"9e$ts, store re#eren$es to the a$tual data. This se$tion

    introdu$es the #ollo%ing key%ords used to de$lare re#eren$e ty&es@

    Y !lass

    Y 7nter#a$e

    Y elegate

    This se$tion also introdu$es the #ollo%ing "uiltin re#eren$e ty&es@

    Y o"9e$t

    Y string

    What is the difference 2etween structures and enumeration?.

    nlike $lasses, stru$ts are value ty&es and do not reuire hea& allo$ation. / varia"le o# a stru$t ty&e dire$tly$ontains the data o# the stru$t, %hereas a varia"le o# a $lass ty&e $ontains a re#eren$e to the data. They are derived#rom )ystem.+alueTy&e $lass.

    EnumH/n enum ty&e is a distin$t ty&e that de$lares a set o# named $onstants.They are strongly ty&ed $onstants.

    They are uniue ty&es that allo% to de$lare sym"oli$ names to integral values. Enums are value ty&es, %hi$h means

    they $ontain their o%n value, $an't inherit or "e inherited #rom and assignment $o&ies the value o# one enum toanother.

    &u"li$ enum Grade

    Z

    /,

    B,

    !

    [

    What is names"aces?.

    Names&a$e is a logi$al naming s$heme #or grou& related ty&es.)ome $lass ty&es that logi$ally "elong together they

    $an "e &ut into a $ommon names&a$e. They &revent names&a$e $ollisions and they &rovide s$o&ing. They are

    im&orted as using in !? or 7m&orts in +isual Basi$. 7t seems as i# these dire$tives s&e$i#y a &arti$ular assem"ly,

    "ut they don't. / names&a$e $an s&an multi&le assem"lies, and an assem"ly $an de#ine multi&le names&a$es. 1hen

    the $om&iler needs the de#inition #or a $lass ty&e, it tra$ks through ea$h o# the di##erent im&orted names&a$es to thety&e name and sear$hes ea$h re#eren$ed assem"ly until it is #ound.

    Names&a$es $an "e nested. This is very similar to &a$kages in Java as #ar as s$o&ing is $on$erned.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 -

  • 7/26/2019 c and Aspnet Faqs

    17/55

    C# and ASP.Net FAQ

    9ow do (ou create shared assem2!ies?.

    Just look through the de#inition o# /ssem"lies..

    Y /n /ssem"ly is a logi$al unit o# $ode

    Y /ssem"ly &hysi$ally e6ist as ::s or EEs

    Y Ane assem"ly $an $ontain one or more #iles

    Y The $onstituent #iles $an in$lude any #ile ty&es like image #iles, te6t #iles et$. along %ith ::s or EEs

    Y 1hen you $om&ile your sour$e $ode "y de#ault the e6e(dll generated is a$tually an assem"ly Y nless your $ode is "undled as assem"ly it $an not "e used in any other a&&li$ation

    Y 1hen you talk a"out version o# a $om&onent you are a$tually talking a"out version o# the assem"ly to %hi$h

    the $om&onent "elongs.

    Y Every assem"ly #ile $ontains in#ormation a"out itsel#. This in#ormation is $alled as /ssem"ly ani#est.

    Follo%ing ste&s are involved in $reating shared assem"lies @

    Y !reate your ::(EE sour$e $ode

    Y Generate uniue assem"ly name using )N utility

    Y )ign your ::(EE %ith the &rivate key "y modi#ying /ssem"ly7n#o #ile

    Y !om&ile your ::(EE

    Y Pla$e the resultant ::(EE in glo"al assem"ly $a$he using /: utility

    What is &!o2a! assem2!( cache?Ea$h $om&uter %here the $ommon language runtime is installed has a ma$hine%ide $ode $a$he $alled the glo"al

    assem"ly $a$he. The glo"al assem"ly $a$he stores assem"lies s&e$i#i$ally designated to "e shared "y several

    a&&li$ations on the $om&uter.

    There are several %ays to de&loy an assem"ly into the glo"al assem"ly $a$he@

    X se an installer designed to %ork %ith the glo"al assem"ly $a$he. This is the &re#erred o&tion #or installing

    assem"lies into the glo"al assem"ly $a$he.

    X se a develo&er tool $alled the Glo"al /ssem"ly !a$he tool =Ga$util.e6e>, &rovided "y the .NET Frame%ork

    )*.

    X se 1indo%s E6&lorer to drag assem"lies into the $a$he.

    What is 1S%?.

    1hen $om&iling to managed $ode, the $om&iler translates your sour$e $ode into i$roso#t intermediate language

    =)7:>, %hi$h is a !Pinde&endent set o# instru$tions that $an "e e##i$iently $onverted to native $ode. )7:in$ludes instru$tions #or loading, storing, initialiing, and $alling methods on o"9e$ts, as %ell as instru$tions #orarithmeti$ and logi$al o&erations, $ontrol #lo%, dire$t memory a$$ess, e6$e&tion handling, and other o&erations.

    Be#ore $ode $an "e run, )7: must "e $onverted to !Ps&e$i#i$ $ode, usually "y a 9ustintime =J7T> $om&iler.

    Be$ause the $ommon language runtime su&&lies one or more J7T $om&ilers #or ea$h $om&uter ar$hite$ture it

    su&&orts, the same set o# )7: $an "e J7T$om&iled and run on any su&&orted ar$hite$ture.1hen a $om&iler &rodu$es )7:, it also &rodu$es metadata. etadata des$ri"es the ty&es in your $ode, in$luding

    the de#inition o# ea$h ty&e, the signatures o# ea$h ty&e's mem"ers, the mem"ers that your $ode re#eren$es, and other

    data that the runtime uses at e6e$ution time. The )7: and metadata are $ontained in a &orta"le e6e$uta"le =PE>

    #ile that is "ased on and e6tends the &u"lished i$roso#t PE and $ommon o"9e$t #ile #ormat =!AFF> used

    histori$ally #or e6e$uta"le $ontent. This #ile #ormat, %hi$h a$$ommodates )7: or native $ode as %ell as metadata,

    ena"les the o&erating system to re$ognie $ommon language runtime images. The &resen$e o# metadata in the #ile

    along %ith the )7: ena"les your $ode to des$ri"e itsel#, %hi$h means that there is no need #or ty&e li"raries or7nter#a$e e#inition :anguage =7:>. The runtime lo$ates and e6tra$ts the metadata #rom the #ile as needed during

    e6e$ution.

    What is >it com"i!ers?.how man( are aai!a2!e in c!r?

    Just7nTime $om&iler it $onverts the language that you %rite in .Net into ma$hine language that a $om&uter $an

    understand. there are to ty&es o# J7Ts one is memory o&timied K other is &er#orma$e o&timied.

    What is tracin&?Where it used.E"!ain few methods aai!a2!e

    Tra$ing re#ers to $olle$ting in#ormation a"out the a&&li$ation %hile it is running. Iou use tra$ing in#ormation totrou"leshoot an a&&li$ation.

    Tra$ing allo%s us to o"serve and $orre$t &rogramming errors. Tra$ing ena"les you to re$ord in#ormation in various

    log #iles a"out the errors that might o$$ur at run time. Iou $an analye these log #iles to #ind the $ause o# the errors.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 C

  • 7/26/2019 c and Aspnet Faqs

    18/55

    C# and ASP.Net FAQ

    7n .NET %e have o"9e$ts $alled Tra$e :isteners. / listener is an o"9e$t that re$eives the tra$e out&ut and out&uts itsome%here that some%here $ould "e a %indo% in your develo&ment environment, a #ile on your hard drive, a

    1indo%s Event log, a )U: )erver or Ara$le data"ase, or any other $ustomied data store.

    The )ystem.iagnosti$s names&a$e &rovides the inter#a$es, $lasses, enumerations and stru$tures that are used #or

    tra$ing The )ystem.iagnosti$s names&a$e &rovides t%o $lasses named Tra$e and e"ug that are used #or %riting

    errors and a&&li$ation e6e$ution in#ormation in logs.

    /ll Tra$e :isteners have the #ollo%ing #un$tions. Fun$tionality o# these #un$tions is same e6$e&t that the target

    media #or the tra$ing out&ut is determined "y the Tra$e :istener.ethod Name

    ;esult Fail Aut&uts the s&e$i#ied te6t %ith the !all )ta$k.

    1rite Aut&uts the s&e$i#ied te6t.

    1rite:ine Aut&uts the s&e$i#ied te6t and a $arriage return.

    Flush Flushes the out&ut "u##er to the target media.

    !lose !loses the out&ut stream in order to not re$eive the tra$ing(de"ugging out&ut.

    9ow to set the de2u& mode?

    e"ug ode #or /)P.NET a&&li$ations To set /)P.NET a&&&li$ation in de"ugging mode, edit the a&&li$ation's

    %e".$on#ig and assign the de"ug attri"ute in \ $om&ilation H se$tion to true as sho% "elo%@

    \ $on#iguration H

    \ system.%e" H

    \ $om&ilation de#ault:anguage

  • 7/26/2019 c and Aspnet Faqs

    19/55

    C# and ASP.Net FAQ

    What are the deried c!asses from m!$eader and m!Writer?

    Both ml;eader and ml1riter are a"stra$t "ase $lasses, %hi$h de#ine the #un$tionality that all derived $lasses

    must su&&ort.

    There are three $on$rete im&lementations o# ml;eader@

    .mlTe6t;eader

    2.mlNode;eader

    L.ml+alidating;eader

    There are t%o $on$rete im&lementations o# ml1riter@ .mlTe6t1riter

    2.mlNode1riter

    mlTe6t;eader and mlTe6t1riter su&&ort reading data to(#rom te6t"ased stream, %hile mlNode;eader and

    mlNode1riter are designed #or %orking %ith inmemory A tree stru$ture. The $ustom readers and %riters $an

    also "e develo&ed to e6tend the "uiltin #un$tionality o# ml;eader and ml1riter.

    What is mana&ed and unmana&ed code?

    The .NET #rame%ork &rovides several $ore runtime servi$es to the &rograms that run %ithin it #or e6am&le

    e6$e&tion handling and se$urity. For these servi$es to %ork, the $ode must &rovide a minimum level o# in#ormation

    to the runtime. i.e., $ode e6e$uting under the $ontrol o# the !:; is $alled managed $ode. For e6am&le, any $ode

    %ritten in !? or +isual Basi$ .NET is managed $ode.

    !ode that runs outside the !:; is re#erred to as unmanaged $ode. !A $om&onents, /$tive $om&onents, and

    1inL2 /P7 #un$tions are e6am&les o# unmanaged $ode.9ow (ou de"!o( .NET assem2!ies?

    Ane %ay is sim&ly use 6$o&y. others are use and the setu& &ro9e$ts in .net. and one more %ay is use o# nontu$h

    de&loyment.

    What is 6!o2a!i3ationa and oca!i3ation ?

    Glo"aliation is the &ro$ess o# $reating an a&&li$ation that meets the needs o# users #rom multi&le $ultures. 7t

    in$ludes using the $orre$t

    $urren$y, date and time #ormat, $alendar, %riting dire$tion, sorting rules, and other issues. /$$ommodating these

    $ultural di##eren$es in an a&&li$ation is $alled lo$aliation.sing $lasses o# )ystem.Glo"aliation names&a$e, you

    $an set a&&li$ation's $urrent $ulture.

    This $an "e a$hieved "y using any o# the #ollo%ing L a&&roa$hes.

    . ete$t and redire$t

    2. ;untime ad9ustment L. sing )atellite assem"lies.

    Whate are $esource Fi!es ? 9ow are the( used in .NET?

    ;esour$e #iles are the #iles $ontaining data that is logi$ally de&loyed %ith an a&&li$ation.These #iles $an $ontain

    data in a num"er o# #ormats in$luding strings, images and &ersisted o"9e$ts. 7t has the main advantage o# 7# %e storedata in these #iles then %e don't need to $om&ile these i# the data get $hanged. 7n .NET %e "asi$ally reuire them

    storing $ulture s&e$i#i$ in#ormations "y lo$aliing a&&li$ation's resour$es. Iou $an de&loy your resour$es using

    satellite assem"lies.

    4ifference 2etween 4is"ose and Fina!!i3e method?

    Finalie method is used to #ree the memory used "y some unmanaged resour$es like %indo% handles =81N>. 7t's

    similar to the destru$tor synta6 in !?. The G! $alls this method %hen it #ounds no more re#eren$es to the o"9e$t.

    But, 7n some $ases %e may need release the memory used "y the resour$es e6&li$itely.To release the memorye6&li$itly %e need to im&lement the is&ose method o# 7is&osa"le inter#a$e.

    What is enca"su!ation ?

    En$a&sulation is the a"ility to hide the internal %orkings o# an o"9e$t's "ehavior and its data. For instan$e, let's say

    you have a o"9e$t named Bike and this o"9e$t has a method named start=>. 1hen you $reate an instan$e o# a Bike

    o"9e$t and $all its start=> method you are not %orried a"out %hat ha&&ens to a$$om&lish this, you 9ust %ant to make

    sure the state o# the "ike is $hanged to 'running' a#ter%ards. This kind o# "ehavior hiding is en$a&sulation and it

    makes &rogramming mu$h easier.

    9ow can (ou "reent (our c!ass to 2e inherated further?

    By setting )ealed *ey %ord

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 4

  • 7/26/2019 c and Aspnet Faqs

    20/55

    C# and ASP.Net FAQ

    &u"li$ sealed $lass PlanetZ

    (($ode goes here

    [

    $lass oon@Planet

    Z

    ((Not allo%ed as "ase $lass is sealed

    [

    What is 6;%4 and wh( we need to use it and in what condition? 9ow this is created.

    / G7 is a 25"it integer =- "ytes> that $an "e used a$ross all $om&uters and net%orks %herever a uniue

    identi#ier is reuired. )u$h an identi#ier has a very lo% &ro"a"ility o# "eing du&li$ated. +isual )tudio .NET 7E has

    a utility under the tools menu to generate G7s.

    Wh( do (ou need to seria!i3e.?

    1e need to serialie the o"9e$t,i# you %ant to &ass o"9e$t #rom one $om&uter(a&&li$ation domain to another.Pro$ess

    o# $onverting $om&le6 o"9e$ts into stream o# "ytes that $an "e &ersisted or trans&orted.Names&a$e #or serialiation

    is )ystem.;untime.)erialiation.The 7)erialia"le inter#a$e allo%s you to make any $lass )erialia"le..NET

    #rame%ork #eatures 2 serialiing method.

    .Binary )erialiation 2.: )erialiationWhat is in!ine schema< how does it works?

    )$hemas $an "e in$luded inside o# : #ile is $alled 7nline )$hemas.This is use#ul %hen it is in$onvenient to

    &hysi$ally se&rate the s$hema and the : do$ument./ s$hema is an : do$ument that de#ines the stru$ture,

    $onstraints, data ty&es, and relationshi&s o# the elements that $onstitute the data $ontained inside the :

    do$ument or in another : do$ument.)$hema $an "e an e6ternal #ile %hi$h uses the ) or ; e6tension

    $alled e6ternal s$hema. 7nline s$hema $an take &la$e even %hen validation is turned o##.

    4escri2e the adanta&es of writin& a mana&ed code a""!ication instead of unmana&ed one. What's ino!ed

    in certain "iece of code 2ein& mana&ed?

    /dvantage in$ludes automati$ gar"age $olle$tion,memory management,se$urity,ty&e $he$king,versioning

    anaged $ode is $om&iled #or the .NET runtime environment. 7t runs in the !ommon :anguage ;untime =!:;>,

    %hi$h is the heart o# the .NET Frame%ork. The !:; &rovides servi$es su$h as se$urity,

    memory management, and $rosslanguage integration. anaged a&&li$ations %ritten to take advantage o# the#eatures o# the !:; &er#orm more e##i$iently and sa#ely, and take "etter advantage o# develo&ers e6isting e6&ertisein languages that su&&ort the .NET Frame%ork.

    nmanaged $ode in$ludes all $ode %ritten "e#ore the .NET Frame%ork %as introdu$edQthis in$ludes $ode %ritten

    to use !A, native 1inL2, and +isual Basi$ -. Be$ause it does not run inside the .NET environment, unmanaged

    $ode $annot make use o# any .NET managed #a$ilities.

    What are mu!ticast de!e&ates ? &ie me an eam"!e ?

    elegate that $an have more than one element in its invo$ation :ist.

    using )ystem

    names&a$e )am&leulti!astelegate

    Z

    $lass ulti!ast

    Z &u"li$ delegate string strulti!ast=string s>

    [

    [

    ain!lass de#ines the stati$ methods having same signature as delegate.

    using )ystem

    names&a$e )am&leulti!astelegateZ

    &u"li$ $lass ain!lass

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 20

  • 7/26/2019 c and Aspnet Faqs

    21/55

    C# and ASP.Net FAQ

    Z &u"li$ ain!lass=>

    Z

    [

    &u"li$ stati$ string Jum&=string s>

    Z

    !onsole.1rite:ine=Jum&>

    return )tring.Em&ty [

    &u"li$ stati$ string ;un=string s>

    Z

    !onsole.1rite:ine=;un>

    return )tring.Em&ty

    [

    &u"li$ stati$ string 1alk=string s>

    Z

    !onsole.1rite:ine=1alk>

    return )tring.Em&ty

    [

    [[

    The ain $lass@

    using )ystem

    using )ystem.Threading

    names&a$e )am&leulti!astelegate

    Z

    &u"li$ $lass ainulti!astelegate

    Z

    &u"li$ stati$ void ain=>

    Z ulti!ast.strulti!ast ;un,1alk,Jum& ulti!ast.strulti!ast myelegate

    (((here mydelegate used the !om"ine method o# )ystem.ulti$astelegate

    (((and the delegates $om"ine

    myelegate)ystem.elegate.!om"ine=;un,1alk>

    [

    [

    [

    Can a nested o2ect 2e used in Seria!i3ation ?

    Ies. 7# a $lass that is to "e serialied $ontains re#eren$es to o"9e$ts o# other $lasses, and i# those $lasses have "een

    marked as serialia"le, then their o"9e$ts are serialied too.4ifference 2etween int and int)- ?

    Both are same. )ystem.7ntL2 is a .NET $lass. 7nt is an alias name #or )ystem.7ntL2.

    4escri2e the difference 2etween a Thread and a Process?

    / Pro$ess is an instan$e o# an running a&&li$ation. /nd a thread is the E6e$ution stream o# the Pro$ess. / &ro$ess

    $an have multi&le Thread.

    1hen a &ro$ess starts a s&e$i#i$ memory area is allo$ated to it. 1hen there is multi&le thread in a &ro$ess, ea$h

    thread gets a memory #or storing the varia"les in it and &lus they $an a$$ess to the glo"al varia"les %hi$h is$ommon #or all the thread. Eg./ i$roso#t 1ord is a /&&li$ation. 1hen you o&en a %ord #ile,an instan$e o# the

    1ord starts and a &ro$ess is allo$ated to this instan$e %hi$h has one thread.

    !reated "y Sat(anara(ana Puada !reated on )*+,*-/ )0+0 A1 2

  • 7/26/2019 c and Aspnet Faqs

    22/55

    C# and ASP.Net FAQ

    What is the difference 2etween an E:E and a 4?

    Iou $an $reate an o"9e$ts o# ll "ut not o# the EE.

    ll is an 7nPro$ess !om&onent %hereas EE is an AtPro$ess !om&onent.

    E6e is #or single use %hereas you $an use ll #or multi&le use.

    E6e $an "e started as standalone %here dll $annot "e.

    What is stron&8t("in& ersus weak8t("in&? Which is "referred? Wh(?

    )trong ty&ing im&lies that the ty&es o# varia"les involved in o&erations are asso$iated to the varia"le, $he$ked at

    $om&iletime, and reuire e6&li$it $onversion %eak ty&ing im&lies that they are asso$iated to the value, $he$ked atruntime, and are im&li$itly $onverted as reuired. =1hi$h is &re#erred is a dis&uta"le &oint, "ut 7 &ersonally &re#er

    strong ty&ing "e$ause 7 like my errors to "e #ound as soon as &ossi"le.>

    What is a P%4? 9ow is it usefu! when trou2!eshootin& a s(stem?

    P7 is the &ro$ess 7d o# the a&&li$ation in 1indo%s. 1henever a &ro$ess starts running in the 1indo%s

    environment, it is asso$iated %ith an individual &ro$ess 7d or P7.

    The P7 =Pro$ess 7> a uniue num"er #or ea$h item on the Pro$ess Ta", 7mage Name list. 8o% do you get the P7

    to a&&earM 7n Task anger, sele$t the +ie% menu, then sele$t $olumns and $he$k P7 =Pro$ess 7denti#ier>.

    7n :inu6, P7 is used to de"ug a &ro$ess e6&li$itly. 8o%ever %e $annot do this in a %indo%s environment.

    i$roso#t has laun$hed a )* $alled as i$roso#t A&erations anagement =A>. This uses the P7 to #ind out

    %hi$h dllRs have "een loaded "y a &ro$ess in the memory. This is essentially helul in situations %here the Pro$ess

    %hi$h has a memory leak is to "e tra$ed to a erring dll. Personally 7 have never used a P7, our 1indo%s de"ugger

    does the things reuired to #ind ouWhat is the 6AC? What "ro2!em does it so!e?

    Ea$h $om&uter %here the $ommon language runtime is installed has a ma$hine%ide $ode $a$he $alled the glo"al

    assem"ly $a$he. The glo"al assem"ly $a$he stores assem"lies that are to "e shared "y several a&&li$ations on the

    $om&uter. This area is ty&i$ally the #older under %indo%s or %innt in the ma$hine.

    /ll the assem"lies that need to "e shared a$ross a&&li$ations need to "e done through the Glo"al assem"ly !a$he

    only. 8o%ever it is not ne$essary to install assem"lies into the glo"al assem"ly $a$he to make them a$$essi"le to

    !A intero& or unmanaged $ode.

    There are several %ays to de&loy an assem"ly into the glo"al assem"ly $a$he@

    X se an installer designed to %ork %ith the glo"al assem"ly $a$he. This is the &re#erred o&tion #or installing

    assem"lies into the glo"al assem"ly $a$he.

    X se a develo&er tool $alled the Glo"al /ssem"ly !a$he tool =Ga$util.e6e>, &rovided "y the .NET Frame%ork

    )*.X se 1indo%s E6&lorer to drag assem"lies into the $a$he.G/! solves the &ro"lem o# :: 8ell and :: versioning. nlike earlier situations, G/! $an hold t%o assem"lies

    o# the same name "ut di##erent version. This ensures that the a&&li$ations %hi$h a$$ess a &arti$ular assem"ly

    $ontinue to a$$ess the same assem"ly even i# another version o# that assem"ly is installed on that ma$hine.

    4escri2e what an %nterface is and how its different from a C!ass.