You are on page 1of 46

1.Whatisanassembly?

Assembliesarethebasicbuildingblocksrequiredforanyapplicationtofunctioninthe.NETrealm.Theyarepartiallycompiledcodelibrariesthatformthe
fundamentalunitofdeployment,versioning,activationscoping,reuse,andsecurity.Typically,assembliesprovideacollectionoftypesandresourcesthat
worktogethertoformalogicalunitoffunctionality.Theyarethesmallestdeployableunitsofcodein.NET.Comparedtotheexecutablefilesassembliesare
farmorereliable,moresecure,andeasytomanage.AnassemblycontainsalotmorethantheMicrosoftIntermediateLanguage(MSIL)codethatis
compiledandrunbytheCommonLanguageRuntime(CLR).Inotherwords,youcansaythatanassemblyisasetofoneormoremodulesandclasses
compiledinMSIL,andmetadatathatdescribestheassemblyitself,aswellasthefunctionalitiesoftheassemblyclasses.

2.Namethedifferentcomponentsofanassembly.

Anassemblyisalogicalunitthatismadeupofthefollowingfourdifferenttypesofcomponents:
Assemblymanifest

MSILsourcecode

Typemetadata

Resources

3.Whatarethedifferenttypesofassemblies?Explainthemindetail.

Thefollowingarethetwotypesofassemblies:
PrivateAssemblyReferstotheassemblythatisusedbyasingleapplication.Privateassembliesarekeptinalocalfolderinwhichtheclient
applicationhasbeeninstalled.

PublicorSharedAssemblyReferstotheassemblythatisallowedtobesharedbymultipleapplications.AsharedassemblymustresideinGlobal
AssemblyCache(GAC)withastrongnameassignedtoit.
Forexample,imaginethatyouhavecreatedaDLLcontaininginformationaboutyourbusinesslogic.ThisDLLcanbeusedbyyourclientapplication.In
ordertoruntheclientapplication,theDLLmustbeincludedinthesamefolderinwhichtheclientapplicationhasbeeninstalled.Thismakestheassembly
privatetoyourapplication.NowsupposethattheDLLneedstobereusedindifferentapplications.Therefore,insteadofcopyingtheDLLineveryclient
applicationfolder,itcanbeplacedintheglobalassemblycacheusingtheGACtool.Theseassembliesarecalledsharedassemblies.

4.CanoneDLLfilecontainthecompiledcodeofmorethanone.NETlanguage?
No,aDLLfilecancontainthecompiledcodeofonlyoneprogramminglanguage.

5.WhatisthemaximumnumberofclassesthatcanbecontainedinaDLLfile?

ThereisnolimittothemaximumnumberofclassesthatcanbecontainedinaDLLfile.

6.Whatisasatelliteassembly?

Satelliteassembliesareassembliesthatareusedtodeploylanguageandculturespecificresourcesforanapplication.Inanapplication,aseparateproduct
IDisassignedtoeachlanguageandasatelliteassemblyisinstalledinalanguagespecificsubdirectory.
7.Isversioningapplicabletoprivateassemblies?

No,versioningisnotapplicabletoprivateassembliesastheseassembliesresideintheirindividualfolders.VersioningcanbeappliedtoGAConly.

8.Whatismetadata?

Anassemblymetadatadescribeseverydatatypeandmemberdefinedinthecode.Itstoresthedescriptionofanassembly,suchasname,version,culture,
publickeyofanassemblyalongwiththetypesexported,otherassembliesdependentonthisassembly,andsecuritypermissionsneededtorunthe
application.Inaddition,itstoresthedescriptionoftypes,suchasthename,visibility,baseclass,interfacesimplemented,andmembers,suchasmethods,
fields,properties,events,andnestedtypes.

Italsostoresattributes.Metadataisstoredinbinaryformat.Therefore,metadataofanassemblyissharableamongapplicationsthatexecuteonvarious
platforms.Itcanalsobeexportedtootherapplicationstogiveinformationabouttheservicesandvariousfeaturesofanapplication.

9.WhatisAssemblyManifest?

Assembliesmaintainalltheirinformationinaspecialunitcalledthemanifest.Everyassemblyhasamanifest.

ThefollowingsarethecontentsofanAssemblyManifest:
AssemblynameRepresentsatextstringthatspecifiestheassembly'sname.

VersionnumberRepresentsamajorandminorversionnumber,aswellasarevisionandbuildnumber.TheCL.Rmakesuseofthesenumbersto
enforceversionpolicy.

CultureRepresentsinformationofthecultureorlanguage,whichtheassemblysupports.Anassemblyisacontainerofonlyresourcescontaining
cultureorlanguagespecificinformation.

StrongnameinformationRepresentsthepublickeyfromthepublisher,ifastrongnameisassignedtoanassembly.

ListofallfilesintheassemblyRepresentsahashofeachfilecontainedintheassemblyandafilename.

TypereferenceinformationRepresentstheinformationusedattheruntimetomapatypereferencetothefilethatcontainsitsdeclarationand
implementation.

InformationonreferencedassembliesRepresentsalistofotherassembliesthatarestaticallyreferencedbytheassembly.Eachreference
includesthenamesofdependentassemblies,assemblymetadata(version,culture,operatingsystem,andsoon),andpublickey,iftheassemblyis
strongnamed.

10.WhatisthevalueoftheCopyLocalpropertywhenyouaddanassemblyintheGAC?

False.

11.WhatisNativeImageGenerator?

TheNativeImageGenerator(Ngen.exe)isatoolthatcreatesanativeimagefromanassemblyandstoresthatimagetonativeimagecacheonthe
computer.Whenever,anassemblyisrun,thisnativeimageisautomaticallyusedtocompiletheoriginalassembly.Inthisway,thistoolimprovesthe
performanceofthemanagedapplicationbyloadingandexecutinganassemblyfaster.

Notethatnativeimagesarefilesthatconsistofcompiledprocessorspecificmachinecode.TheNgen.exetoolinstallsthesefilesontothelocalcomputer.

12.NametheMSILDisassemblerutilitythatparsesany.NETFrameworkassemblyandshowstheinformationinhumanreadableformat

TheIldasm.exeutility.
13.WhatisthesignificanceoftheStrongNametool?

TheStrongNameutility(sn.exe)helpsincreatinguniquepublicprivatekeypairfilesthatarecalledstrongnamefilesandsigningassemblieswiththem.It
alsoallowskeymanagement,signaturegeneration,andsignatureverification.

14.Howcandifferentversionsofprivateassembliesbeusedinthesameapplicationwithoutarebuild?

Youcanusedifferentversionsofprivateassembliesinthesameapplicationwithoutarebuildbyspecifyingtheassemblyversionin
theAssemblyInfo.csorAssemblyInfo.vbfile.

15.WhatisGlobalAssemblyCache(GAC)?

GACisacentralrepository(cache)inasysteminwhichassembliesareregisteredtoshareamongvariousapplicationsthatexecuteonlocalorremote
machines..NETFrameworkprovidestheGACtool(gacutil.exeutility),whichisusedtoviewandchangethecontentofGACofasystem.Addingnew
assembliestoGACandremovingassembliesfromGACaresomeofthetasksthatcanbeperformedbyusingthegacutil.exeutility.GACcancontain
multipleversionsofthesame.NETassembly.CLRchecksGACforarequestedassemblybeforeusinginformationofconfigurationfiles.

Thegacutil.exe/i<assemblyname>isthecommandthatisusedtoinstallanassemblyinGAC.UsersusetheCommandPromptofVisualStudioto
installanassemblyinGACbyusingthiscommand.

YoucanseealltheassembliesinstalledintheGACusingtheGACviewer,whichislocatedatthe<WinDrive>:<WinDir>\assemblydirectory,
where<WinDir>iswindowsinWindowsXPorwindowsinWindowsVistaorWinNTinWindows2000.Apartfromthelistofassemblies,theassemblyviewer
alsoshowsrelevantinformation,suchastheglobalassemblyname,version,culture,andthepublickeytoken.

16.Whereistheinformationregardingtheversionoftheassemblystored?

Informationfortheversionofassemblyisstoredinsidetheassemblymanifest.

17.Discusstheconceptofstrongnames.

Whenever,anassemblyisdeployedinGACtomakeitshared,astrongnameneedstobeassignedtoitforitsuniqueidentification.Astrongnamecontains
anassembly'scompleteidentitytheassemblyname,versionnumber,andcultureinformationofanassembly.Apublickeyandadigitalsignature,
generatedovertheassembly,arealsocontainedinastrongname.AstrongnamemakesanassemblyidenticalinGAC.
18.Whatisthedifferencebetween.EXEand.DLLfiles?

EXE
1. Itisanexecutablefile,whichcanberunindependently.

2. EXEisanoutprocesscomponent,whichmeansthatitrunsinaseparateprocess.

3. Itcannotbereusedinanapplication.

4. Ithasamainfunction.

DLL
1. ItisDynamicLinkLibrarythatisusedasapartofEXEorotherDLLs.Itcannotberunindependently.

2. Itrunsintheapplicationprocessmemory,soitiscalledasinprocesscomponent.

3. Itcanbereusedinanapplication.

4. Itdoesnothaveamainfunction.
19.Whichutilityallowsyoutoreferenceanassemblyinanapplication?

Anassemblycanbereferencedbyusingthegacutil.exeutilitywiththe/roption.The/roptionrequiresareferencetype,areferenceID,anda
description.

20.TheAssemblyInfo.csfilestorestheassemblyconfigurationinformationandotherinformation,suchastheassemblyname,version,company
name,andtrademarkinformation.(True/False).

True.
1.Whatis.NETFramework?

.NETFrameworkisacompleteenvironmentthatallowsdeveloperstodevelop,run,anddeploythefollowingapplications:

Consoleapplications

WindowsFormsapplications

WindowsPresentationFoundation(WPF)applications

Webapplications(ASP.NETapplications)

Webservices

Windowsservices

ServiceorientedapplicationsusingWindowsCommunicationFoundation(WCF)

WorkflowenabledapplicationsusingWindowsWorkflowFoundation(WF)

.NETFrameworkalsoenablesadevelopertocreatesharablecomponentstobeusedindistributedcomputingarchitecture.NETFrameworksupportsthe
objectorientedprogrammingmodelformultiplelanguages,suchasVisualBasic,VisualC#,andVisualC++..NETFrameworksupportsmultiple
programminglanguagesinamannerthatallowslanguageinteroperability.Thisimpliesthateachlanguagecanusethecodewritteninsomeother
language.

2.Whatarethemaincomponentsof.NETFramework?

.NETFrameworkprovidesenormousadvantagestosoftwaredevelopersincomparisontotheadvantagesprovidedbyotherplatforms.Microsofthasunited
variousmodernaswellasexistingtechnologiesofsoftwaredevelopmentin.NETFramework.Thesetechnologiesareusedbydeveloperstodevelophighly
efficientapplicationsformodernaswellasfuturebusinessneeds.Thefollowingarethekeycomponentsof.NETFramework:

.NETFrameworkClassLibrary

CommonLanguageRuntime

DynamicLanguageRuntimes(DLR)
ApplicationDomains

RuntimeHost

CommonTypeSystem

MetadataandSelfDescribingComponents

CrossLanguageInteroperability

.NETFrameworkSecurity

Profiling

SidebySideExecution

3.Listthenewfeaturesaddedin.NETFramework4.0.

Thefollowingarethenewfeaturesof.NETFramework4.0:

ImprovedApplicationCompatibilityandDeploymentSupport

DynamicLanguageRuntime

ManagedExtensibilityFramework

ParallelProgrammingframework

ImprovedSecurityModel

NetworkingImprovements

ImprovedCoreASP.NETServices

ImprovementsinWPF4

ImprovedEntityFramework(EF)

IntegrationbetweenWCFandWF

4.WhatisanIL?
IntermediateLanguageisalsoknownasMSIL(MicrosoftIntermediateLanguage)orCIL(CommonIntermediateLanguage).All.NETsourcecodeis
compiledtoIL.IListhenconvertedtomachinecodeatthepointwherethesoftwareisinstalled,oratruntimebyaJustInTime(JIT)compiler.

5.WhatisManifest?

AssemblymetadataisstoredinManifest.Manifestcontainsallthemetadataneededtodothefollowingthings
Versionofassembly.

Securityidentity.

Scopeoftheassembly.

Resolvereferencestoresourcesandclasses.

TheassemblymanifestcanbestoredinaPEfileeither(an.exeor).dllwithMicrosoft
intermediatelanguage(MSILcodewithMicrosoftintermediatelanguage(MSIL)codeorina
standalonePEfile,thatcontainsonlyassemblymanifestinformation.

6.Whatarecodecontracts?

Codecontractshelpyoutoexpressthecodeassumptionsandstatementsstatingthebehaviorofyourcodeinalanguageneutralway.Thecontractsare
includedintheformofpreconditions,postconditionsandobjectinvariants.Thecontractshelpyoutoimprovetestingbyenablingruntimechecking,static
contractverification,anddocumentationgeneration.

TheSystem.Diagnostics.Contractsnamespacecontainsstaticclassesthatareusedtoexpresscontractsinyourcode.
NametheclassesthatareintroducedintheSystem.Numericsnamespace.

ThefollowingtwonewclassesareintroducedintheSystem.Numericsnamespace:
BigIntegerReferstoanonprimitiveintegraltype,whichisusedtoholdavalueofanysize.Ithasnolowerandupperlimit,makingitpossibleforyouto
performarithmeticcalculationswithverylargenumbers,evenwiththenumberswhichcannotholdbydoubleorlong.

ComplexRepresentscomplexnumbersandenablesdifferentarithmeticoperationswithcomplexnumbers.Anumberrepresentedintheforma+bi,
whereaistherealpart,andbistheimaginarypart,isacomplexnumber.

Whatismanagedextensibilityframework?

Managedextensibilityframework(MEF)isanewlibrarythatisintroducedasapartof.NET4.0andSilverlight4.Ithelpsinextendingyourapplicationbyproviding
greaterreuseofapplicationsandcomponents.MEFprovidesawayforhostapplicationtoconsumeexternalextensionswithoutanyconfigurationrequirement.

Explainmemorymappedfiles.

Memorymappedfiles(MMFs)allowyoumapthecontentofafiletothelogicaladdressofanapplication.Thesefilesenablethemultipleprocessesrunningonthe
samemachinetosharedatawitheachOther.TheMemoryMappedFile.CreateFromFile()methodisusedtoobtainaMemoryMappedFileobjectthat
representsapersistedmemorymappedfilefromafileondisk.

ThesefilesareincludedintheSystem.IO.MemoryMappedFilesnamespace.Thisnamespacecontainsfourclassesandthreeenumerationstohelpyouaccess
andsecureyourfilemappings.

WhatisCommonTypeSystem(CTS)?

CTSisthecomponentofCLRthroughwhich.NETFrameworkprovidessupportformultiplelanguagesbecauseitcontainsatypesystemthatiscommonacross
allthelanguages.TwoCTScompliantlanguagesdonotrequiretypeconversionwhencallingthecodewritteninonelanguagefromwithinthecodewrittenin
anotherlanguage.CTSprovideabasesetofdatatypesforallthelanguagessupportedby.NETFramework.Thismeansthatthesizeofintegerandlongvariables
issameacrossall.NETcompliantprogramminglanguages.However,eachlanguageusesaliasesforthebasedatatypesprovidedbyCTS.Forexample,CTS
usesthedatatypesystem.int32torepresenta4byteintegervaluehowever,VisualBasicusesthealiasintegerforthesamewhereas,C#usesthealiasint.This
isdoneforthesakeofclarityandsimplicity.

Giveabriefintroductiononsidebysideexecution.Cantwoapplications,oneusingprivateassemblyandtheotherusingthesharedassemblybe
statedassidebysideexecutables?

SidebysideexecutionenablesyoutorunmultipleversionsofanapplicationorcomponentandCLRonthesamecomputeratthesametime.Asversioningis
applicableonlytosharedassembliesandnottoprivateassemblies,twoapplications,oneusingaprivateassemblyandotherusingasharedassembly,cannotbe
statedassidebysideexecutables.

Whichmethoddoyouusetoenforcegarbagecollectionin.NET?

TheSystem.GC.Collect()method.
13.StatethedifferencesbetweentheDispose()andFinalize().

CLRusestheDisposeandFinalizemethodstoperformgarbagecollectionofruntimeobjectsof.NETapplications.

TheFinalizemethodiscalledautomaticallybytheruntime.CLRhasagarbagecollector(GC),whichperiodicallychecksforobjectsinheapthatareno
longerreferencedbyanyobjectorprogram.ItcallstheFinalizemethodtofreethememoryusedbysuchobjects.TheDisposemethodiscalledbythe
programmer.Disposeisanothermethodtoreleasethememoryusedbyanobject.TheDisposemethodneedstobeexplicitlycalledincodetodereference
anobjectfromtheheap.TheDisposemethodcanbeinvokedonlybytheclassesthatimplementtheIDisposableinterface.

14.Whatiscodeaccesssecurity(CAS)?

Codeaccesssecurity(CAS)ispartofthe.NETsecuritymodelthatpreventsunauthorizedaccessofresourcesandoperations,andrestrictsthecodeto
performparticulartasks.

15.Differentiatebetweenmanagedandunmanagedcode?

ManagedcodeisthecodethatisexecuteddirectlybytheCLRinsteadoftheoperatingsystem.Thecodecompilerfirstcompilesthemanagedcodeto
intermediatelanguage(IL)code,alsocalledasMSILcode.Thiscodedoesn'tdependonmachineconfigurationsandcanbeexecutedondifferent
machines.

UnmanagedcodeisthecodethatisexecuteddirectlybytheoperatingsystemoutsidetheCLRenvironment.Itisdirectlycompiledtonativemachinecode
whichdependsonthemachineconfiguration.
Inthemanagedcode,sincetheexecutionofthecodeisgovernedbyCLR,theruntimeprovidesdifferentservices,suchasgarbagecollection,type
checking,exceptionhandling,andsecuritysupport.Theseserviceshelpprovideuniformityinplatformandlanguageindependentbehaviorofmanaged
codeapplications.Intheunmanagedcode,theallocationofmemory,typesafety,andsecurityisrequiredtobetakencareofbythedeveloper.Ifthe
unmanagedcodeisnotproperlyhandled,itmayresultinmemoryleak.ExamplesofunmanagedcodeareActiveXcomponentsandWin32APIsthat
executebeyondthescopeofnativeCLR.

16.Whataretuples?

Tupleisafixedsizecollectionthatcanhaveelementsofeithersameordifferentdatatypes.Similartoarrays,ausermusthavetospecifythesizeofatuple
atthetimeofdeclaration.Tuplesareallowedtoholdupfrom1to8elementsandiftherearemorethan8elements,thenthe8thelementcanbedefinedas
anothertuple.Tuplescanbespecifiedasparameterorreturntypeofamethod.
17.HowcanyouturnonandturnoffCAS?

YOUcanusetheCodeAccessSecurityTool(Caspol.exe)toturnsecurityonandoff.

Toturnoffsecurity,typethefollowingcommandatthecommandprompt:
caspolsecurityoff

Toturnonsecurity,typethefollowingcommandatthecommandprompt:
caspolsecurityon

Inthe.NETFramework4.0,forusingCaspol.exe,youfirstneedtosetthe<LegacyCasPolicy>elementtotrue.

18.Whatisgarbagecollection?Explainthedifferencebetweengarbagecollectionsin.NET4.0andearlierversions.

Garbagecollectionpreventsmemoryleaksduringexecutionofprograms.Garbagecollectorisalowpriorityprocessthatmanagestheallocationand
deallocationofmemoryforyourapplication.Itchecksfortheunreferencedvariablesandobjects.IfGCfindsanyobjectthatisnolongerusedbythe
application,itfreesupthememoryfromthatobject.

GChaschangedabitwiththeintroductionof.NET4.0.In.NET4.0,theGC.Collect()methodcontainsthefollowingoverloadedmethods:

GC.Collect(int)
GC.Collect(int,GCCollectionMode)

Anothernewfeatureintroducedin.NETistonotifyyouwhentheGC.Collect()methodisinvokedandcompletedsuccessfullybyusingdifferentmethods.
The.NET4.0supportsanewbackgroundgarbagecollectionthatreplacestheconcurrentgarbagecollectionusedinearlierversions.ThisconcurrentGC
allocatesmemorywhilerunningandusescurrentsegment(whichis16MBonaworkstation)forthat.Afterthat,allthreadsaresuspended.Incaseof
backgroundGC,aseparateephemeralGCgen0andgen1canbestarted,whilethefullGCgen0,1,and2isalreadyrunning.
19.HowdoesCASworks?

TherearetwokeyconceptsofCASsecuritypolicycodegroupsandpermissions.Acodegroupcontainsassembliesinitinamannerthateach.NET
assemblyisrelatedtoaparticularcodegroupandsomepermissionsaregrantedtoeachcodegroup.Forexample,usingthedefaultsecuritypolicy,a
controldownloadedfromaWebsitebelongstotheZone,Internetcodegroup,whichadherestothepermissionsdefinedbythenamedpermissionset.
(Normally,thenamedpermissionsetrepresentsaveryrestrictiverangeofpermissions.)

Assemblyexecutioninvolvesthefollowingsteps:

1. Evidencesaregatheredaboutassembly.

2. Dependingonthegatheredevidences,theassemblyisassignedtoacodegroup.

3. Securityrightsareallocatedtotheassembly,dependingonthecodegroup.

4. Assemblyrunsaspertherightsassignedtoit.

20.WhatisDifferencebetweenNameSpaceandAssembly?

Followingarethedifferencesbetweennamespaceandassembly:
Assemblyisphysicalgroupingoflogicalunits,Namespace,logicallygroupsclasses.

Namespacecanspanmultipleassembly.

21.Mentiontheexecutionprocessformanagedcode.

Apieceofmanagedcodeisexecutedasfollows:

Choosingalanguagecompiler

CompilingthecodetoMSIL

CompilingMSILtonativecode

Executingthecode.
22.Isthereawaytosuppressthefinalizeprocessinsidethegarbagecollectorforciblyin.NET?

UsetheGC.SuppressFinalize()methodtosuppressthefinalizeprocessinsidethegarbagecollectorforciblyin.NET.

23.Howcanyouinstantiateatuple?

Thefollowingaretwowaystoinstantiateatuple:

Usingthenewoperator.Forexample,

Tuple<String,int>t=newTuple<String,int>("Hellow",2)

UsingtheCreatefactorymethodavailableintheTupleclass.Forexample,

Tuple<int,int,int>t=Tuple.Create<int,int,int>(2,4,5)

24.Whichistherootnamespaceforfundamentaltypesin.NETFramework?

System.Objectistherootnamespaceforfundamentaltypesin.NETFramework.
WhataretheimprovementsmadeinCASin.NET4.0?

TheCASmechanismin.NETisusedtocontrolandconfiguretheabilityofmanagedcode.Earlier,asthispolicywasapplicableforonlynativeapplications,the
securityguaranteewaslimited.Therefore,developersusedtolookforalternatingsolutions,suchasoperatingsystemlevelsolutions.Thisproblemwassolvedin
.NETFramework4byturningoffthemachinewidesecurity.ThesharedandhostedWebapplicationscannowrunmoresecurely.Thesecuritypolicyin.NET
Framework4hasbeensimplifiedusingthetransparencymodel.ThismodelallowsyoutoruntheWebapplicationswithoutconcerningabouttheCASpolicies.

Asaresultofsecuritypolicychangesin.NETFramework4.0,youmayencountercompilationwarningsandruntimeexceptions,ifyourtrytousetheobsoleteCAS
policytypesandmemberseitherimplicitlyorexplicitly.However,youcanavoidthewarningsanderrorsbyusing
the<NetFx40_LegacySecurityPolicy>configurationelementintheruntimesettingsschematooptintotheobsoleteCASpolicybehavior.

WhatisMicrosoftIntermediateLanguage(MSIL)?

The.NETFrameworkisshippedwithcompilersofall.NETprogramminglanguagestodevelopprograms.ThereareseparatecompilersfortheVisualBasic,C#,
andVisualC++programminglanguagesin.NETFramework.Each.NETcompilerproducesanintermediatecodeaftercompilingthesourcecode.The
intermediatecodeiscommonforalllanguagesandisunderstandableonlyto.NETenvironment.ThisintermediatecodeisknownasMSIL.

Whatislazyinitialization?

Lazyinitializationisaprocessbywhichanobjectisnotinitializeduntilitisfirstcalledinyourcode.The.NET4.0introducesanewwrapper
class,System.Lazy<T>,forexecutingthelazyinitializationinyourapplication.Lazyinitializationhelpsyoutoreducethewastageofresourcesandmemory
requirementstoimproveperformance.Italsosupportsthreadsafety.

Howmanytypesofgenerationsarethereinagarbagecollector?

MemorymanagementintheCLRisdividedintothreegenerationsthatarebuildupbygroupingmemorysegments.Generationsenhancethegarbagecollection
performance.Thefollowingarethethreetypesofgenerationsfoundinagarbagecollector:
Generation0Whenanobjectisinitialized,itissaidtobeingeneration0.

Generation1Theobjectsthatareundergarbagecollectionprocessareconsideredtobeingeneration1.
Generation2Whenevernewobjectsarecreatedandaddedtothememory,theyareaddedtogeneration0andtheoldobjectsingeneration1are
consideredtobeingeneration2.

Explaincovarianceandcontravariancein.NETFramework4.0.Giveanexampleforeach.

In.NET4.0,theCLRsupportscovarianceandcontravarianceoftypesingenericinterfacesanddelegates.Covarianceenablesyoutocastagenerictypetoits
basetypes,thatis,youcanassignainstanceoftypeIEnumerable<Tl>toavariableoftypeIEnumerable<T2>where,T1derivesfromT2.Forexample,

IEnumerable<string>str1=newList<string>()
IEnumerable<object>str2=str1

ContravarianceallowsyoutoassignavariableofAction<base>toavariableoftypeAction<derived>.Forexample,

IComparer<object>obj1=GetComparer()
IComparer<string>obj2=obj1

.NETframework4.0usessomelanguagekeywords(outandin)toannotatecovarianceandcontravariance.Outisusedforcovariance,whileinisusedfor
contravariance.

Variancecanbeappliedonlytoreferencetypes,genericinterfaces,andgenericdelegates.Thesecannotbeappliedtovaluetypesandgenerictypes.

Howdoyouinstantiateacomplexnumber?

Thefollowingarethedifferentwaystoassignavaluetoacomplexnumber:

BypassingtwoDoublevaluestoitsconstructor.Thefirstvaluerepresentsthereal,andthesecondvaluerepresentsimaginarypartofacomplexnumber.
Forexample,

Complexc1=newComplex(5,8)/*Itrepresents(5,8)*/
ByassigningaByte,SByte,Intl6,UIntl6,Int32,UInt32,Int64,UInt64,Single,orDoublevaluetoaComplexobject.Theassignedvaluerepresentsthe
realpartofthecomplexnumber,anditsimaginarypartbecomes0.Forexample,

Complexc2=15.3/*Itrepresents(15.3,0)*/

BycastingaDecimalorBigIntegervaluetoaComplexobject.
Forexample,

Complexc3=(Complex)14.7/*Itrepresents(14.7,0)*/

AssigningthevaluereturnedbyanoperatortoaComplexvariable.
Forexample,

Complexc4=c1+c2/*Itrepresents(20.3,8)*/
31.WhatisCommonLanguageSpecification(CLS)?

CLSisasetofbasicrules,whichmustbefollowedbyeach.NETlanguagetobea.NETcompliantlanguage.Itenablesinteroperabilitybetweentwo.NET
compliantlanguages.CLSisasubsetofCTStherefore,thelanguagessupportedbyCLScanuseeachother'sclasslibrariessimilartotheirown.
Applicationprogramminginterfaces(APIs),whicharedesignedbyfollowingtherulesdefinedinCLScanbeusedbyall.NETcompliantlanguages.

32.WhatistheroleoftheJITcompilerin.NETFramework?

TheJITcompilerisanimportantelementofCLR,whichloadsMSILontargetmachinesforexecution.TheMSILisstoredin.NETassembliesafterthe
developerhascompiledthecodewritteninany.NETcompliantprogramminglanguage,suchasVisualBasicandC#.

JITcompilertranslatestheMSILcodeofanassemblyandusestheCPUarchitectureofthetargetmachinetoexecutea.NETapplication.Italsostoresthe
resultingnativecodesothatitisaccessibleforsubsequentcalls.Ifacodeexecutingonatargetmachinecallsanonnativemethod,theJITcompiler
convertstheMSILofthatmethodintonativecode.JITcompileralsoenforcestypesafetyinruntimeenvironmentof.NETFramework.Itchecksforthe
valuesthatarepassedtoparametersofanymethod.

Forexample,theJITcompilerdetectsanyevent,ifausertriestoassigna32bitvaluetoaparameterthatcanonlyaccept8bitvalue.

33.WhatisdifferencebetweenSystem.StringandSystem.StringBuilderclasses?

StringandStringBuilderclassesareusedtostorestringvaluesbutthedifferenceinthemisthatStringisimmutable(readonly)bynature,becausea
valueonceassignedtoaStringobjectcannotbechangedafteritscreation.WhenthevalueintheStringobjectismodified,anewobjectiscreated,in
memory,withanewvalueassignedtotheStringobject.Ontheotherhand,theStringBuilderclassismutable,asitoccupiesthesamespaceevenif
youchangethevalue.TheStringBuilderclassismoreefficientwhereyouhavetoperformalargeamountofstringmanipulation.

34.DescribetherolesofCLRin.NETFramework.

CLRprovidesanenvironmenttoexecute.NETapplicationsontargetmachines.CLRisalsoacommonruntimeenvironmentforall.NETcodeirrespectiveof
theirprogramminglanguage,asthecompilersofrespectivelanguagein.NETFrameworkconverteverysourcecodeintoacommonlanguageknownas
MSILorIL(IntermediateLanguage).

CLRalsoprovidesvariousservicestoexecuteprocesses,suchasmemorymanagementserviceandsecurityservices.CLRperformsvarioustasksto
managetheexecutionprocessof.NETapplications.
TheresponsibilitiesofCLRarelistedasfollows:

Automaticmemorymanagement

GarbageCollection

CodeAccessSecurity

Codeverification

JITcompilationof.NETcode

35.Whatisthedifferencebetweenintandint32.

Thereisnodifferencebetweenintandint32.System.Int32isa.NETClassandintisanaliasnameforSystem.Int32.
Why.NETFramework?
.NET Framework is the most powerful development platform for building a variety of solutions on Windows. For example, using the .NET Framework, you can
createapplicationsforWindowsDesktop,Webapplications,WindowsPhoneapplications,WindowsStoreapplications,WindowsServer,WindowsAzure(cloud)as
wellasBotframeworksandcognitiveservices.
Beforeexploringthe.NETFramework,wefirsthavetounderstandtheissues/painareaswhichdevelopershavefacedinothertechnologies
Programming with Win32 API Earlier we were using Win32 API and C language. This paradigm does not offer Object Oriented Features as C is a
structuredlanguage.Thereisnobetterwayofmemorymanagementeitherasitisdonemanually.UsingPointersisabigpainareafordevelopers.
ProgrammingwithVC++ManyofususeC++andMFSasaprogramminglanguagewhichoffersthefeaturesofObjectOrientedFeatures.HoweverC++is
builtontopofClanguageandhencethedevelopmentcanstillcumbersomeformanynoviceprogrammerswhoaredealingwithmemorymanagementand
pointers.
ProgrammingwithVisualBasic6.0Waybackin1998,VB6.0asadevelopmentlanguagehadmadedevelopmenteffortseasier.Forexampledesigning
complexUI,DataCentricapplicationsandmuchmore.ButVB6.0isnotanobjectorientedlanguageandisoutdatednow.WhendesigningMultithreaded
application,westillhavetogobacktoWin32APIs.
Programming with COM Component Object Model is a specification which is used for developing reusable components which can be called across the
languages like VC++, Delphi. But with COM we also get "DLL Hell". DLL Hell is the issue of maintaining multiple versions of a component for multiple
applications.
Under.NETFramework,manyoftheseproblemshavebeenaddressedandresolved.
Microsoft.NETFrameworkprovidesahugeno.ofbenefitscomparedwiththelegacylanguages
NomoreCOMSpecificationsin.NET.So,weautomaticallygetawayfromDLLHell.
Microsoft.NETsupportslanguageintegration.
Microsoft.NETBaseClassLibraryoffersawrapperovermanyrawAPIcallswhichcanbeusedinvarious.NETLanguages.
YoucancallCOMcomponentsin.NETand.NETComponentsinCOMusinginteroperability.
ACommonRuntimeEnginesharedbyallthe.NETLanguages.
AsingleframeworktodevelopWindows/Webapplications.
Wehaveno.oflanguageswhichmakedeveloperstoadaptthe.NETFrameworkforapplicationdevelopment.
WhatisBCL?
TheBaseClassLibraryisaCommonLanguageInfrastructure.BCLencapsulatesalargenumberofcommonfunctionalitieswhichareavailabletoallthe.NET
Languages. BCL makes the developers life much simpler while implementing various functionalities like I/O operations, Data access operations, graphical user
interfacesandinterfacestovarioushardwaredevicesbyencapsulatingthemintovariousnamespacesandclasses.Italsoencapsulatestheserviceswhichare
requiredbythelatestrealworldapplications..NETFrameworkapplications,componentsandthecontrolsarebuiltonBCL.
Thereareanumberofnamespacesandtypesavailableundervariousclasslibrariesin.NETframeworkwhichcanbefoundherehttps://msdn.microsoft.com/en
us/library/gg145045(v=VS.110).aspx
ExplainCLR,CTS,CLSunder.NETFramework?
CommonLanguageRuntimeisoneofthemainbuildingblocksofMicrosoft.NETFrameworkwhichisresponsibleforperformingvariousoperationsunder.NET
Framework.

WhenyoudesigntheapplicationusingMicrosoft.NETlanguageslikeC#.NETorVB.NET,thelanguagehasitsowncomplierwhichcompilesthecodeintocommon
formatthatisCIL[CommonIntermediateLanguage].ThenCILgetstargetedtoCLRwhichinturnperformsmanyoperations.ItconvertsCILintoNativecodewith
thehelpofJIT.
CLRalsoperformsvariousotheroperationslikeMemoryManagement,ApplicationExecution,ThreadManagement,Securitychecks,loadtherequiredassemblies
andtheirtypes.ThecodewhichismanagedbyCLRisalsoknownasManagedCode.AllthemanagedlanguagesarehandledbyasingleruntimethatisCLR.
CommonTypeSystem(CTS)defines how the types are defined and used in the Common Language Runtime. CTS provides crosslanguage integration, type
safety,andhighperformancecodeexecution.TheCommonTypeSystemforlanguageintegrationworksasfollows

When you define an integer variable in VB.NET and declare integer in C#.NET, both the languages share the same type which is Int32, available under .NET
Framework.
CTSdefinesruleswhichmustbefollowedbylanguagesinordertomakeobjectswritteninonelanguagecallableinotherlanguages.
Microsoft.NETFrameworkprovidesvariousprimitivedatatypeswhichcanbeusedwhiledevelopingapplicationsusingvariouslanguages.
CommonLanguageSpecification(CLS)isasetofrules.CLSrulesalsodefineasubsetofCTS.BydefiningcomponentsusingCLSfeaturesonly,developers
areguaranteedtomakeuseofthesecomponentsinalltheotherlanguageswhichareCLScompliantlanguages.Mostofthetypeswhicharedefinedunder.NET
frameworkareCLScomplaint.
Whatarethedifferentversionsof.NETFramework?
FollowingarethedifferentversionsoftheMicrosoft.NETFramework
Therearetwomoreversionsof.NETFrameworkreleasedafterv4.5..NETFramework4.6wasreleasedinJuly2015andcamewithsupportforanewjustintime
compiler(JIT)for64bitsystemscalledRyuJIT..NETFramework4.6.1wasannouncedinNovember2015.
Whatisanapplicationserver?
AsdefinedinWikipedia,anapplicationserverisasoftwareenginethatdeliversapplicationstoclientcomputersordevices.Theapplicationserverrunsyourserver
code.SomewellknownapplicationserversareIIS(Microsoft),WebLogicServer(BEA),JBoss(RedHat),WebSphere(IBM).
CompareC#andVB.NET
Adetailedcomparisoncanbefoundoverhere.
Whatisabaseclassandderivedclass?
Aclassisatemplateforcreatinganobject.Theclassfromwhichotherclassesderivefundamentalfunctionalityiscalledabaseclass.Fore.g.IfClassYderives
fromClassX,thenClassXisabaseclass.
Theclasswhichderivesfunctionalityfromabaseclassiscalledaderivedclass.IfClassYderivesfromClassX,thenClassYisaderivedclass.
Whatisanextenderclass?
Anextenderclassallowsyoutoextendthefunctionalityofanexistingcontrol.ItisusedinWindowsformsapplicationstoaddpropertiestocontrols.
Ademonstrationofextenderclassescanbefoundoverhere.
Whatisinheritance?
Inheritancerepresentstherelationshipbetweentwoclasseswhereonetypederivesfunctionalityfromasecondtypeandthenextendsitbyaddingnewmethods,
properties,events,fieldsandconstants.
C#supporttwotypesofinheritance:
Implementationinheritance
Interfaceinheritance
Whatisimplementationandinterfaceinheritance?
Whenaclass(type)isderivedfromanotherclass(type)suchthatitinheritsallthemembersofthebasetypeitisImplementationInheritance.
Whenatype(classorastruct)inheritsonlythesignaturesofthefunctionsfromanothertypeitisInterfaceInheritance.
IngeneralClassescanbederivedfromanotherclass,hencesupportImplementationinheritance.AtthesametimeClassescanalsobederivedfromoneormore
interfaces.HencetheysupportInterfaceinheritance.
Source:Exforsys.
Whatisinheritancehierarchy?
Theclasswhichderivesfunctionalityfromabaseclassiscalledaderivedclass.Aderivedclasscanalsoactasabaseclassforanotherclass.Thusitispossible
tocreateatreelikestructurethatillustratestherelationshipbetweenallrelatedclasses.Thisstructureisknownastheinheritancehierarchy.
Howdoyoupreventaclassfrombeinginherited?
InVB.NETyouusetheNotInheritablemodifiertopreventprogrammersfromusingtheclassasabaseclass.InC#,usethesealedkeyword.
Whenshouldyouuseinheritance?
Readthis.
ExplainDifferentTypesofConstructorsinC#?
Therearefourdifferenttypesofconstructorsyoucanwriteinaclass
1.DefaultConstructor
2.ParameterizedConstructor
3.CopyConstructor
4.StaticConstructor
Readmoreaboutitathttp://www.dotnetcurry.com/csharp/1193/csharpconstructortypesinterviewquestion
DefineOverriding?
Overridingisaconceptwhereamethodinaderivedclassusesthesamename,returntype,andargumentsasamethodinitsbaseclass.Inotherwords,ifthe
derivedclasscontainsitsownimplementationofthemethodratherthanusingthemethodinthebaseclass,theprocessiscalledoverriding.
Canyouusemultipleinheritancein.NET?
.NETsupportsonlysingleinheritance.Howeverthepurposeisaccomplishedusingmultipleinterfaces.
Whydontwehavemultipleinheritancein.NET?
There are several reasons for this. In simple words, the efforts are more, benefits are less. Different languages have different implementation requirements of
multipleinheritance.Soinordertoimplementmultipleinheritance,weneedtostudytheimplementationaspectsofallthelanguagesthatareCLRcompliantand
thenimplementacommonmethodologyofimplementingit.Thisistoomuchofefforts.Moreovermultipleinterfaceinheritanceverymuchcoversthebenefitsthat
multipleinheritancehas.
WhatisanInterface?
An interface is a standard or contract that contains only the signatures of methods or events. The implementation is done in the class that inherits from this
interface.Interfacesareprimarilyusedtosetacommonstandardorcontract.
WhenshouldyouuseabstractclassvsinterfaceorWhatisthedifferencebetweenanabstractclassandinterface?
Iwouldsuggestyoutoreadthis.Thereisagoodcomparisongivenoverhere.
Whatareeventsanddelegates?
An event is a message sent by a control to notify the occurrence of an action. However it is not known which object receives the event. For this reason, .NET
providesaspecialtypecalledDelegatewhichactsasanintermediarybetweenthesenderobjectandreceiverobject.
Whatisbusinesslogic?
Itisthefunctionalitywhichhandlestheexchangeofinformationbetweendatabaseandauserinterface.
Whatisacomponent?
Componentisagroupoflogicallyrelatedclassesandmethods.AcomponentisaclassthatimplementstheIComponentinterfaceorusesaclassthatimplements
IComponentinterface.
Whatisacontrol?
Acontrolisacomponentthatprovidesuserinterface(UI)capabilities.
Whatarethedifferencesbetweenacontrolandacomponent?
Thedifferencescanbestudiedoverhere.
Whataredesignpatterns?
Designpatternsarecommonsolutionstocommondesignproblems.
Whatisaconnectionpool?
Aconnectionpoolisacollectionofconnectionswhicharesharedbetweentheclientsrequestingone.Oncetheconnectionisclosed,itreturnsbacktothepool.
Thisallowstheconnectionstobereused.
Whatisaflatfile?
Aflatfileisthenamegiventotext,whichcanbereadorwrittenonlysequentially.
Whatarefunctionalandnonfunctionalrequirements?
Functionalrequirementsdefinesthebehaviorofasystemwhereasnonfunctionalrequirementsspecifyhowthesystemshouldbehaveinotherwordstheyspecify
thequalityrequirementsandjudgethebehaviorofasystem.
E.g.
FunctionalDisplayachartwhichshowsthemaximumnumberofproductssoldinaregion.
NonfunctionalThedatapresentedinthechartmustbeupdatedevery5minutes.
WhatisanAssembly?ExplaindifferenttypesofAssemblies?
Anassemblyisafinaldeployableunitwhichcanversionedandsecured.Theassemblycanalsobetermedasareusablecollectionoftypesandresourceswhich
work together as a logical unit of functionalities in .NET. .NET assemblies can be designed as executable (.EXE) or reusable component (.DLL). An assembly
containsoneormoremanagedtypeswhichcanbemadeaccessibletotheunitoroutsidetheunit.
Assemblygetsdividedintofourdifferentparts.
Manifest.
TypeMetadata.
IntermediateLanguage.
Resources.
Manifest contains information about the assembly like Version of an assembly, the public key in case the assembly is shared assembly and the culture
information.Italsocontainsthesecuritydemandstoverifythisassembly.CLRusesthemanifesttoloadtheassembly.
TypeMetadatagivesthecompleteinformationaboutthetypeswhichareavailableintheassemblylikeClass,Structure,Interface,Enum,andthemethods,their
parameters.Thecompilersautomaticallygeneratethismetadata.YoucanmakeuseofthisTypeMetadatatodynamicallyloadthetypesusing.NETReflection.
Intermediate Language It a code generated by the language specific compiler. It is also known as Machine independent code which can be compiled on one
machineandcanbedeployedonanother.CLRtargetsthiscodetoJITtoconvertitintoprocessordependoncodewhichcanbefurtherexecuted.
ResourcesAssemblycanalsocontaintheembeddedresourceslikeicons,images,stringtablesmediaclips.
Youcanseethisinformationusinga.NETframeworkutilitycalledILDASM.EXE
Microsoft.NETsupportdifferenttypesofassemblies.
PrivateAssemblyPrivateAssembliesaretheassemblieswhichareonlyknowntotheapplicationtowhichithasbeenreferenced.Bydefault,theassemblies
arealwaysprivatewhenyoucreateandreferencethem.Theprivateassemblygetsstoredintheapplicationfolderwhichisusingtheassembly.
Privateassembliesareidentifiedwiththehelpofnameofanassemblyandversionofanassembly.Buttheversionsdoesnotreallycomeintothepictureasthe
referencedassemblyisinthesamefolderofyourapplication.
Shared/Global/PublicAssemblyGlobal/PublicAssembliesaretheassemblieswhicharesharedacrossmultipleapplications.Theseassembliesareinstalled
intoGlobalAssemblyCachewhichactsasasharedareaforalltheassemblies.
GlobalAssemblyisidentifiedwiththefourpartassemblynameNameofanAssembly,Versionofanassembly,andCultureofanAssemblyandPublicKeyToken
ofanassembly.GlobalAssemblyCachecancontaindifferentversionsofanassembly.
Youcaninstallapublic/globalassemblyintoGlobalAssemblyCache[GAC]usingGACUTIL.EXEtool.
SatelliteAssemblySatelliteAssembliesareusedtobuildmultilingualassembliesforapplications.Satelliteassembliescontaininformationaboutthecultures.
SatelliteassembliesareusedtodisplaythedatainmultiplelanguagesaccordingtoCountry/Region.
Whatistheglobalassemblycache(GAC)?
GACisamachinewidecacheofassembliesthatallows.NETapplicationstosharelibraries.GACsolvessomeoftheproblemsassociatedwithdlls(DLLHell).
Whatisastack?Whatisaheap?Givethedifferencesbetweenthetwo?
Stackisaplaceinthememorywherevaluetypesarestored.Heapisaplaceinthememorywherethereferencetypesarestored.
Checkthislinkforthedifferences.
Whatisinstrumentation?
Itistheabilitytomonitoranapplicationsothatinformationabouttheapplicationsprogress,performanceandstatuscanbecapturedandreported.
Whatiscodereview?
Theprocessofexaminingthesourcecodegenerallythroughapeer,toverifyitagainstbestpractices.
Whatislogging?
Loggingistheprocessofpersistinginformationaboutthestatusofanapplication.
Whataremockups?
Mockups are a set of designs in the form of screens, diagrams, snapshots etc., that helps verify the design and acquire feedback about the applications
requirementsandusecases,atanearlystageofthedesignprocess.
WhatisaForm?
Aformisarepresentationofanywindowdisplayedinyourapplication.Formcanbeusedtocreatestandard,borderless,floating,modalwindows.
Whatisamultipledocumentinterface(MDI)?
Auserinterfacecontainerthatenablesausertoworkwithmorethanonedocumentatatime.E.g.MicrosoftExcel.
Whatisasingledocumentinterface(SDI)?
Auserinterfacethatiscreatedtomanagegraphicaluserinterfacesandcontrolsintosinglewindows.E.g.MicrosoftWord
WhatisBLOB?
ABLOB(binarylargeobject)isalargeitemsuchasanimageoranexerepresentedinbinaryform.
WhatisClickOnce?
ClickOnce is a new deployment technology that allows you to create and publish selfupdating applications that can be installed and run with minimal user
interaction.
Whatisobjectrolemodeling(ORM)?
It is a logical model for designing and querying database models. There are various ORM tools in the market like CaseTalk, Microsoft Visio for Enterprise
Architects,Infagonetc.
Whatisaprivateassembly?
Aprivateassemblyislocaltotheinstallationdirectoryofanapplicationandisusedonlybythatapplication.
Whatisasharedassembly?
Asharedassemblyiskeptintheglobalassemblycache(GAC)andcanbeusedbyoneormoreapplicationsonamachine.
Whatisthedifferencebetweenuserandcustomcontrols?
Usercontrolsareeasiertocreatewhereascustomcontrolsrequireextraeffort.
Usercontrolsareusedwhenthelayoutisstaticwhereascustomcontrolsareusedindynamiclayouts.
Ausercontrolcannotbeaddedtothetoolboxwhereasacustomcontrolcanbe.
AseparatecopyofausercontrolisrequiredineveryapplicationthatusesitwhereassincecustomcontrolsarestoredintheGAC,onlyasinglecopycanbeused
byallapplications.
Wheredocustomcontrolsreside?
Intheglobalassemblycache(GAC).
Whatisathirdpartycontrol?
Athirdpartycontrolisonethatisnotcreatedbytheownersofaproject.Theyareusuallyusedtosavetimeandresourcesandreusethefunctionalitydeveloped
byothers(thirdparty).
Whatisabinaryformatter?
Binaryformatterisusedtoserializeanddeserializeanobjectinbinaryformat.
WhatisBoxing/Unboxing?
Boxingisusedtoconvertvaluetypestoobject.
E.g.intx=1
objectobj=x
Unboxingisusedtoconverttheobjectbacktothevaluetype.
E.g.inty=(int)obj
Boxing/unboxingisquietanexpensiveoperation.
WhatisaCOMCallableWrapper(CCW)?
CCWisawrappercreatedbythecommonlanguageruntime(CLR)thatenablesCOMcomponentstoaccess.NETobjects.
WhatisaRuntimeCallableWrapper(RCW)?
RCWisawrappercreatedbythecommonlanguageruntime(CLR)toenable.NETcomponentstocallCOMcomponents.
Whatisadigitalsignature?
Adigitalsignatureisanelectronicsignatureusedtoverify/guranteetheidentityoftheindividualwhoissendingthemessage.
Whatisgarbagecollectionandexplainitsdifferentgenerations?
GarbagecollectorisapartofCommonLanguageRuntime,whichdoesautomaticmemorymanagementforyourapplication.Whenyoucreateanobjectinyour
application,CLRallocatesthememoryforthatobjectonManagedHeap.
Garbagecollectorgivesnumberofbenefitslike
AutomaticMemoryManagementYoucanbuildyourapplicationwithoutthinkingabouthowtofreethememoryasGarbageCollectorgetscalledautomaticallyby
CLR.
GarbageCollectordoesproficientmemorymanagementforyourobjects.
GarbageCollectordoesautomaticreclaimofthememoryforthoseobjectswhicharenotinuseandwhicharemarkedfordeletion.
Garbagecollectorallocatesthememoryforobjectsinsuchawaythatoneobjectwillnotbeabletouseotherobjectdataaccidently.

The Managed Heap is a memory area where a series of managed objects are stored and managed. As shown in the above diagram, the managed heap gets
dividedintothreedifferentsectionswhichareknownasGenerations.
Generation0Thisisthefirstgenerationundermanagedheapwhichisusedtostoreandmanageshortlivedobjects.Allsmallsizeobjectsusuallygetallocated
on Generation 0. When garbage collector reclaims the memory, it always reclaims the memory from generation 0 by default. The objects which are survived in
Generation0willbepushedtowardsthegeneration1.
Generation1 This generation again contain the shortlived objects and the objects which are survived from Generation 0. The objects which are survived in
Generation1willbepushedtowardsthegeneration2.
Generation2Thisgenerationcontainsthelonglivedobjectswhicharesurvivedfrommultiplegenerationsandareusedtilltheprocessisrunning.
GarbageCollectorfirstlooksforthefreememoryingeneration0whichcanbeusedtoallocatethememoryforthenewobject.Theobjectsarealwayscreatedin
contagious memory. If the garbage collector finds sufficient memory for the new object, it does not search for the dead object and hence memory allocation
processisalwaysfaster.Butincase,sufficientmemoryisnotavailablethengarbagecollectorreclaimsthememoryoftheobjectswhicharedeadornotgetting
usedforalongtime.
WhenGarbagecollectorgetsexecuted,itfirstofall,findsalltheliveobjects.Afterthisgarbagecollectorupdatestheaddressesofobjectswhichwillbecompacted.
Thenitreclaimsthememoryofallthedeadobjects.Oncethememoryisreclaimed,itmovesthelivedobjectstothenextGeneration.Forexample,theobjects
which live through in Generation 0 will be moved towards Generation 1. The objects which survived in generation 1 will be moved towards Generation 2. The
objectswhichsurvivedinGeneration2willstayinGeneration2only.
WhatisApplicationDomainandhowdoesitwork?
Windows Operating Systems load a set of resources like .EXE, DLLs and allocate the memory for those resources in an area called as Process. Windows OS
createsaseparateandisolatedareaforeachrunningapplication.Makingseparateisolationareaforeachapplication,makestheprocessmoresecureandstable.
Incase,oneprocessfails,itdoesnotaffecttheotherprocess.
.NETapplications,however,arenothostedliketraditionalapplicationsbyWindowsOperatingSystem.Under.NET,.EXEsarehostedunderaprocessbylogical
partitioningwhichisknownas"ApplicationDomain".Nowyoucanhostmultipleapplicationdomainsunderonesingleprocess.

Application Domains consume less memory and power for processing the applications compared to the traditional processes for each application. In case one
application domain fails, the other application domain will work asis without any effects. You can also stop one application domain without affecting another
applicationdomainorwithoutstoppinganentireprocess.
OneApplicationDomaincannotshare/accessthedatafromotherApplicationDomainwhichisrunningwithinthesameDomainorotherDomain.
Whatisglobalization?
Globalizationistheprocessofcustomizingapplicationsthatsupportmultipleculturesandregions.
Whatislocalization?
Localizationistheprocessofcustomizingapplicationsthatsupportagivencultureandregions.
WhatisMIME?
ThedefinitionofMIMEorMultipurposeInternetMailExtensionsasstatedinMSDNisMIMEisastandardthatcanbeusedtoincludecontentofvarioustypesina
singlemessage.MIMEextendstheSimpleMailTransferProtocol(SMTP)formatofmailmessagestoincludemultiplecontent,bothtextualandnontextual.Parts
ofthemessagemaybeimages,audio,ortextindifferentcharactersets.TheMIMEstandardderivesfromRFCssuchas2821and2822.Quotedfromhere.
IhopeyoulikedthesequestionsandIthankyouforviewingthem.IthankPravinDabadeforcontributingsomeofthe.NETInterviewquestionandanswers.
1.Definevariableandconstant.

Avariablecanbedefinedasameaningfulnamethatisgiventoadatastoragelocationinthecomputermemorythatcontainsavalue.Everyvariable
associatedwithadatatypedetermineswhattypeofvaluecanbestoredinthevariable,forexampleaninteger,suchas100,adecimal,suchas30.05,ora
character,suchas'A'.

Youcandeclarevariablesbyusingthefollowingsyntax:

<Data_type><variable_name>

Aconstantissimilartoavariableexceptthatthevalue,whichyouassigntoaconstant,cannotbechanged,asincaseofavariable.Constantsmustbe
initializedatthesametimetheyaredeclared.Youcandeclareconstantsbyusingthefollowingsyntax:

constintinterestRate=10

2.Whatisadatatype?Howmanytypesofdatatypesaretherein.NET?

Adatatypeisadatastorageformatthatcancontainaspecifictypeorrangeofvalues.Wheneveryoudeclarevariables,eachvariablemustbeassigneda
specificdatatype.Somecommondatatypesincludeintegers,floatingpoint,characters,andstrings.Thefollowingarethetwotypesofdatatypesavailable
in.NET:
ValuetypeReferstothedatatypethatcontainsthedata.Inotherwords,theexactvalueorthedataisdirectlystoredinthisdatatype.Itmeans
thatwhenyouassignavaluetypevariabletoanothervariable,thenitcopiesthevalueratherthancopyingthereferenceofthatvariable.Whenyou
createavaluetypevariable,asinglespaceinmemoryisallocatedtostorethevalue(stackmemory).Primitivedatatypes,suchasint,float,and
charareexamplesofvaluetypevariables.

ReferencetypeReferstoadatatypethatcanaccessdatabyreference.Referenceisavalueoranaddressthataccessesaparticulardataby
address,whichisstoredelsewhereinmemory(heapmemory).Youcansaythatreferenceisthephysicaladdressofdata,wherethedataisstored
inmemoryorinthestoragedevice.Somebuiltinreferencetypesvariablesin.Netarestring,array,andobject.

3.MentionthetwomajorcategoriesthatdistinctlyclassifythevariablesofC#programs.

VariablesthataredefinedinaC#programbelongtotwomajorcategories:valuetypeandreferencetype.Thevariablesthatarebasedonvaluetype
containavaluethatiseitherallocatedonastackorallocatedinlineinastructure.Thevariablesthatarebasedonreferencetypesstorethememory
addressofavariable,whichinturnstoresthevalueandareallocatedontheheap.Thevariablesthatarebasedonvaluetypeshavetheirowncopyofdata
andthereforeoperationsdoneononevariabledonotaffectothervariables.Thereferencetypevariablesreflectthechangesmadeinthereferring
variables.

Predicttheoutputofthefollowingcodesegment:

intx=42
inty=12
intw
objecto
o=x
w=y*(int)o
Console.WriteLine(w)

/*Theoutputofthecodeis504.*/

4.Whichstatementisusedtoreplacemultipleifelsestatementsincode.

InVisualBasic,theSelectCasestatementisusedtoreplacemultipleIfElsestatementsandinC#,theswitchcasestatementisusedtoreplace
multipleifelsestatements.

5.Whatisthesyntaxtodeclareanamespacein.NET?

In.NET,thenamespacekeywordisusedtodeclareanamespaceinthecode.

ThesyntaxfordeclaringanamespaceinC#is:
namespaceUserNameSpace

ThesyntaxfordeclaringanamespaceinVBis:
NamespaceUserNameSpace

6.Whatisthedifferencebetweenconstantsandreadonlyvariablesthatareusedinprograms?
Constantsperformthesametasksasreadonlyvariableswithsomedifferences.Thedifferencesbetweenconstantsandreadonlyare

Constants:
1. Constantsaredealtwithatcompiletime.

2. Constantssupportsvaluetypevariables.

3. Constantsshouldbeusedwhenitisveryunlikelythatthevaluewilleverchange.

Readonly:
1. Readonlyvariablesareevaluatedatruntime.

2. Readonlyvariablescanholdreferencetypevariables.

3. Readonlyvariablesshouldbeusedwhenruntimecalculationisrequired.
7.DifferentiatebetweenthewhileandforloopinC#.

Thewhileandforloopsareusedtoexecutethoseunitsofcodethatneedtoberepeatedlyexecuted,unlesstheresultofthespecifiedconditionevaluates
tofalse.Theonlydifferencebetweenthetwoisintheirsyntax.Theforloopisdistinguishedbysettinganexplicitloopvariable.

8.Whatisanidentifier?

Identifiersarenorthingbutnamesgiventovariousentitiesuniquelyidentifiedinaprogram.Thenameofidentifiersmustdifferinspellingorcasing.For
example,MyProgandmyProgaretwodifferentidentifiers.Programminglanguages,suchasC#andVisualBasic,strictlyrestricttheprogrammersfrom
usinganykeywordasidentifiers.Programmerscannotdevelopaclasswhosenameispublic,because,publicisakeywordusedtospecifythe
accessibilityofdatainprograms.

9.Whatdoesabreakstatementdointheswitchstatement?

Theswitchstatementisaselectioncontrolstatementthatisusedtohandlemultiplechoicesandtransfercontroltothecasestatementswithinitsbody.
ThefollowingcodesnippetshowsanexampleoftheuseoftheswitchstatementinC#:

switch(choice)
{
case1:
console.WriteLine("First")
break
case2:
console.WriteLine("Second")
break
default:
console.WriteLine("Wrongchoice")
break
}

Inswitchstatements,thebreakstatementisusedattheendofacasestatement.ThebreakstatementismandatoryinC#anditavoidsthefallthrough
ofonecasestatementtoanother.

10.Explainkeywordswithexample.
Keywordsarethosewordsthatarereservedtobeusedforaspecifictask.Thesewordscannotbeusedasidentifiers.Youcannotuseakeywordtodefine
thenameofavariableormethod.Keywordsareusedinprogramstousethefeaturesofobjectorientedprogramming.

Forexample,theabstractkeywordisusedtoimplementabstractionandtheinheritskeywordisusedtoimplementinheritancebyderivingsubclassesin
C#andVisualBasic,respectively.

ThenewkeywordisuniversallyusedinC#andVisualBasictoimplementencapsulationbycreatingobjects.

11.BrieflyexplainthecharacteristicsofvaluetypevariablesthataresupportedintheC#programminglanguage.

Thevariablesthatarebasedonvaluetypesdirectlycontainvalues.ThecharacteristicsofvaluetypevariablesthataresupportedinC#programming
languageareasfollows:
AllvaluetypevariablesderiveimplicitlyfromtheSystem.ValueTypeclass

Youcannotderiveanynewtypefromavaluetype

Valuetypeshaveanimplicitdefaultconstructorthatinitializesthedefaultvalueofthattype

Thevaluetypeconsistsoftwomaincategories:
StructsSummarizessmallgroupsofrelatedvariables.

EnumerationsConsistsofasetofnamedconstants.

12.GivethesyntaxofusingthewhileloopinaC#program.

ThesyntaxofusingthewhileloopinC#is:

while(condition)//condition
{
//statements
}

YoucanfindanexampleofusingthewhileloopinC#:

inti=0
inti=0
while(i<5)
{
Console.WriteLine("{0}",i)
i++
}

Theoutputoftheprecedingcodeis:01234.
13.Whatisaparameter?ExplainthenewtypesofparametersintroducedinC#4.0.

Aparameterisaspecialkindofvariable,whichisusedinafunctiontoprovideapieceofinformationorinputtoacallerfunction.Theseinputsarecalled
arguments.InC#,thedifferenttypesofparametersareasfollows:
ValuetypeRefersthatyoudonotneedtoprovideanykeywordwithaparameter.

ReferencetypeRefersthatyouneedtomentiontherefkeywordwithaparameter.

OutputtypeRefersthatyouneedtomentiontheoutkeywordwithaparameter.

OptionalparameterReferstothenewparameterintroducedinC#4.0.Itallowsyoutoneglecttheparametersthathavesomepredefineddefault
values.Theexampleofoptionalparameterisasfollows:

publicintSum(inta,intb,intc=0,intd=0)/*canddisoptional*/
Sum(10,20)//10+20+0+0
Sum(10,20,30)//10+20+30+0
Sum(10,20,30,40)//10+20+30+40

NamedparameterReferstothenewparameterintroducedinC#4.0.Nowyoucanprovideargumentsbynameratherthanposition.Theexample
ofthenamedparameterisasfollows:

publicvoidCreateAccount(stringname,stringaddress="unknown",intage=0)
CreateAccount("Sara",age:30)
CreateAccount(address:"India",name:"Sara")

14.BrieflyexplainthecharacteristicsofreferencetypevariablesthataresupportedintheC#programminglanguage.

Thevariablesthatarebasedonreferencetypesstorereferencestotheactualdata.Thekeywordsthatareusedtodeclarereferencetypesare:
1. ClassReferstotheprimarybuildingblockfortheprograms,whichisusedtoencapsulatevariablesandmethodsintoasingleunit.

2. InterfaceContainsonlythesignaturesofmethods,properties,events,orindexers.

3. DelegateReferstoareferencetypethatisusedtoencapsulateanamedoranonymousmethod.

15.Whatarethedifferenttypesofliterals?
Aliteralisatextualrepresentationofaparticularvalueofatype.

ThedifferenttypesofliteralsinVisualBasicare:
BooleanLiteralsReferstotheTrueandFalseliteralsthatmaptothetrueandfalsestate,respectively.

IntegerLiteralsReferstoliteralsthatcanbedecimal(base10),hexadecimal(base16),oroctal(base8).

FloatingPointLiteralsReferstoanintegerliteralfollowedbyanoptionaldecimalpointBydefault,afloatingpointliteralisoftypeDouble.

StringLiteralsReferstoasequenceofzeroormoreUnicodecharactersbeginningandendingwithanASCIIdoublequotecharacter.

CharacterLiteralsRepresentsasingleUnicodecharacteroftheChartype.

DateLiteralsRepresentstimeexpressedasavalueoftheDatetype.

NothingReferstoaliteralthatdoesnothaveatypeandisconvertibletoalltypesinthetypesystem.

ThedifferenttypesofliteralsinC#are:
BooleanliteralsReferstotheTrueandFalseliteralsthatmaptothetrueandfalsestates,respectively.

IntegerliteralsReferstoliteralsthatareusedtowritevaluesoftypesint,uint,long,andulong.

RealliteralsReferstoliteralsthatareusedtowritevaluesoftypesfloat,double,anddecimal.

CharacterliteralsRepresentsasinglecharacterthatusuallyconsistsofacharacterinquotes,suchas'a'.

StringliteralsReferstostringliterals,whichcanbeoftwotypesinC#:
Aregularstringliteralconsistsofzeroormorecharactersenclosedindoublequotes,suchas"hello".

Averbatimstringliteralconsistsofthe@characterfollowedbyadoublequotecharacter,suchas@"hello".

TheNullliteralRepresentsthenulltype.

16.Whatisthemaindifferencebetweensubprocedureandfunction?

ThesubprocedureisablockofmultiplevisualbasicstatementswithinSubandEndSubstatements.Itisusedtoperformcertaintasks,suchaschanging
propertiesofobjects,receivingorprocessingdata,anddisplayinganoutput.Youcandefineasubprocedureanywhereinaprogram,suchasinmodules,
structures,andclasses.

Wecanalsoprovideargumentsinasubprocedurehowever,itdoesnotreturnanewvalue.
ThefunctionisalsoasetofstatementswithintheFunctionandEndFunctionstatements.Itissimilartosubprocedureandperformsthesametask.The
maindifferencebetweenafunctionandasubprocedureisthatsubproceduresdonotreturnavaluewhilefunctionsdo.

17.Determinetheoutputofthecodesnippet.

inta=29
a
a=++a
Console.WriteLine("Thevalueofais:{0}",a)

/*Theoutputofthecodeis1.*/

18.DifferentiatebetweenBoxingandUnboxing.

Whenavaluetypeisconvertedtoanobjecttype,theprocessisknownasboxingwhereas,whenanobjecttypeisconvertedtoavaluetype,theprocessis
knownasunboxing.

Boxingandunboxingenablevaluetypestobetreatedasobjects.BoxingavaluetypepackagesitinsideaninstanceoftheObjectreferencetype.This
allowsthevaluetypetobestoredonthegarbagecollectedheap.Unboxingextractsthevaluetypefromtheobject.Inthisexample,theintegervariableiis
boxedandassignedtoobjectobj.

Example:

inti=123
objectobj=i/*Thilineboxesi.*/

/*Theobjectobjcanthenbeunboxedandassignedtointegervariablei:*/
i=(int)obj//unboxing
GivethesyntaxofusingtheforloopinC#code?

ThesyntaxofusingtheforloopinC#codeisgivenasfollows:

for(initializerconditionloopexpression)
{
//statements
}

Intheprecedingsyntax,initializeristheinitialvalueofthevariable,conditionistheexpressionthatischeckedbeforetheexecutionoftheforloop,andloop
expressioneitherincrementsordecrementstheloopcounter.

TheexampleofusingtheforloopinC#isshowninthefollowingcodesnippet:

for(inti=0i<5i++)
Console.WriteLine("Hello")

Intheprecedingcodesnippet,thewordHellowillbedisplayedforfivetimesintheoutputwindow.