Вы находитесь на странице: 1из 17

.

co

2.WhatarethetypesofcommentinC#?

Thereare3typesofcommentsinC#.
Singleline(//)
Multi(/**/)
Page/XMLComments(///).

1.WhatisC#?

C#(pronounced"Csharp")isasimple,modern,objectoriented,andtypesafe
programminglanguage.ItwillimmediatelybefamiliartoCandC++programmers.C#
combinesthehighproductivityofRapidApplicationDevelopment(RAD)languages.

3.WhatarethenamespacesusedinC#.NET?

Namespaceisalogicalgroupingofclass.
usingSystem
usingSystem.Collections.Generic
usingSystem.Windows.Forms

er

Simple
Typesafe
Flexible
Objectoriented
Compatible
Consistent
Interoperable
Modern

ar

4.WhatarethecharacteristicsofC#?

ThereareseveralcharacteristicsofC#are:

re

5.Whatarethedifferentcategoriesofinheritance?

InheritanceinObjectOrientedProgrammingisoffourtypes:
Singleinheritance:Containsonebaseclassandonederivedclass.
Hierarchicalinheritance:Containsonebaseclassandmultiplederivedclassesofthe
samebaseclass.
Multilevelinheritance:Containsaclassderivedfromaderivedclass.

Ca

Multipleinheritance:Containsseveralbaseclassesandaderivedclass.
6.Whatarethebasicconceptsofobjectorientedprogramming?

Itisnecessarytounderstandsomeoftheconceptsusedextensivelyinobjectoriented
programming.Theseinclude:
Objects
Classes
Dataabstractionandencapsulation
Inheritance

Polymorphism
DynamicBinding
Messagepassing.

Yes.MultipleinterfacesmaybeinheritedinC#.
8.Whatisinheritance?

7.Canyouinheritmultipleinterfaces?

.co

Inheritanceisderivingthenewclassfromthealreadyexistingone.
9.Definescope?

Scopereferstotheregionofcodeinwhichavariablemaybeaccessed.

10.Whatisthedifferencebetweenpublic,staticandvoid?

public: ThekeywordpublicisanaccessmodifierthattellstheC#compilerthattheMain
methodisaccessiblebyanyone.

ar

static:ThekeywordstaticdeclaresthattheMainmethodisaglobaloneandcanbecalled
withoutcreatinganinstanceoftheclass.Thecompilerstorestheaddressofthemethod
astheentrypointandusesthisinformationtobeginexecutionbeforeanyobjects
arecreated.
void: ThekeywordvoidisatypemodifierthatstatesthattheMainmethoddoesnotreturn
anyvalue.

re

er

11.WhatarethemodifiersinC#?

Abstract
Sealed
Virtual
Const
Event
Extern
Override
Readonly
Static
New

Ca

12.WhatarethetypesofaccessmodifiersinC#?

AccessmodifiersinC#are:
public
protect
private
internal
internalprotect

13.Whatisboxingandunboxing?

ImplicitconversionofvaluetypetoreferencetypeofavariableisknownasBOXING,for
exampleintegertoobjecttypeconversion.
ConversionofreferencetypevariablebacktovaluetypeiscalledasUnBoxing.

14.Whatisobject?

15.WherearethetypesofarraysinC#?

Single-Dimensional
Multidimensional
Jaggedarrays.

.co

Anobjectisaninstanceofaclass.Anobjectiscreatedbyusingoperatornew.Aclass
thatcreatesanobjectinmemorywillcontaintheinformationaboutthevalues
andbehaviors(ormethods)ofthatspecificobject.

16.WhatisthedifferencebetweenObjectandInstance?

Anobjectisaninstanceofaclass.

ar

17.Definedestructors?

Aninstanceofauserdefinedtypeiscalledanobject.Wecaninstantiatemanyobjects
fromoneclass.

Adestructoriscalledforaclassobjectwhenthatobjectpassesoutofscopeorisexplicitly
deleted.Adestructorsasthenameimpliesisusedtodestroytheobjectsthathavebeen
createdbyaconstructors.Likeaconstructor,thedestructorisamemberfunctionwhose
nameisthesameastheclassnamebutisprecisedbyatilde.

er

18.Whatistheuseofenumerateddatatype?

Anenumerateddatatypeisanotheruserdefinedtypewhichprovidesawayforattaching
namestonumberstherebyincreasingcomprehensibilityofthecode.Theenumkeyword
automaticallyenumeratesalistofwordsbyassigningthemvalues0,1,2,andsoon.

re

19.DefineConstructors?

Aconstructorisamemberfunctionwiththesamenameasitsclass.Theconstructoris
invokedwheneveranobjectofitsassociatedclassiscreated.Itiscalledconstructor
becauseitconstructsthevaluesofdatamembersoftheclass.

Ca

20.Whatisencapsulation?

Thewrappingupofdataandfunctionsintoasingleunit(calledclass)isknownas
encapsulation.Encapsulationcontainingandhidinginformationaboutanobject,suchas
internaldatastructuresandcode.
21.Doesc#supportmultipleinheritance?
No,itsimpossiblewhichacceptsmultilevelinheritance.
22.WhatisENUM?

Enumareusedtodefineconstants.
23.Whatisadataset?

ADataSetisaninmemoryrepresentationofdataloadedfromanydatasource.

.co

24.Whatisthedifferencebetweenprivateandpublickeyword?

Private: Theprivatekeywordisthedefaultaccesslevelandmostrestrictiveamongall
otheraccesslevels.Itgivesleastpermissiontoatypeortypemember.Aprivatemember
isaccessibleonlywithinthebodyoftheclassinwhichitisdeclared.
Public:Thepublickeywordismostliberalamongallaccesslevels,withnorestrictionsto
accesswhatsoever.Apublicmemberisaccessiblenotonlyfromwithin,butalsofrom
outside,andgivesfreeaccesstoanymemberdeclaredwithinthebodyoroutside
thebody.
25.Definepolymorphism?

Polymorphismmeansonename,multipleforms.Itallowsustohavemorethanone
functionwiththesamenameinaprogram.Itallowsustohaveoverloadingofoperatorsso
thatanoperationcanexhibitdifferentbehaviorsindifferentinstances.

ar

26.WhatisJaggedArrays?

Ajaggedarrayisanarraywhoseelementsarearrays.

Theelementsofajaggedarraycanbeofdifferentdimensionsandsizes.

er

Ajaggedarrayissometimescalledanarrayofarrays.
27.Whatisanabstractbaseclass?

Anabstractclassisaclassthatisdesignedtobespecificallyusedasabaseclass.An
abstractclasscontainsatleastonepurevirtualfunction.

re

28.Howismethodoverridingdifferentfrommethodoverloading?
Whenoverridingamethod,youchangethebehaviorofthemethodforthederivedclass.
Overloadingamethodsimplyinvolveshavinganothermethodwiththesamenamewithin
theclass.

Ca

29.Whatisthedifferencebetweenref&outparameters?
Anargumentpassedtoarefparametermustfirstbeinitialized.Comparethistoanout
parameter,whoseargumentdoesnothavetobeexplicitlyinitializedbeforebeingpassed
toanoutparameter.
30.WhatistheuseofusingstatementinC#?
Theusingstatementisusedtoobtainaresource,executeastatement,andthendispose
ofthatresource.

31.Whatisserialization?
Serializationistheprocessofconvertinganobjectintoastreamofbytes.

De-serialization istheoppositeprocessofcreatinganobjectfromastreamofbytes.
Serialization/Deserializationismostlyusedtotransportobjects.

.co

32.WhatarethedifferencebetweenStructureandClass?

StructuresarevaluetypeandClassesarereferencetype
Structurescannothavecontractorsordestructors.

Classescanhavebothcontractorsanddestructors.

StructuresdonotsupportInheritance,whileClassessupportInheritance.
33.WhatisdifferencebetweenClassAndInterface?

Class islogicalrepresentationofobject.Itiscollectionofdataandrelatedsubprocedures
withdefination.

ar

Interfaceisalsoaclasscontaingmethodswhichisnothavinganydefinations.Classdoes
notsupportmultipleinheritance.Butinterfacecansupport.
34.WhatisDelegates?

er

Delegatesareatypesafe,objectorientedimplementationoffunctionpointersandare
usedinmanysituationswhereacomponentneedstocallbacktothecomponentthatis
usingit.
35.WhatisAuthenticationandAuthorization?
Authenticationistheprocessofidentifyingusers.Authenticationisidentifying/validating
theuseragainstthecredentials(usernameandpassword).

re

Authorizationperformsafterauthentication.Authorizationistheprocessofgrantingaccess
tothoseusersbasedonidentity.
Authorizationallowingaccessofspecificresourcetouser.
36.Whatisabaseclass?

Ca

Aclassdeclarationmayspecifyabaseclassbyfollowingtheclassnamewithacolonand
thenameofthebaseclass.omittingabaseclassspecificationisthesameasderiving
fromtypeobject.
37.Canthisbeusedwithinastaticmethod?
NoThiscannotbeusedinastaticmethod.Asonlystaticvariables/methodscanbeused
inastaticmethod.
38.Whatisdifferencebetweenconstants,readonlyand,static?


Constants :Thevaluecantbechanged.
Read-only :Thevaluewillbeinitializedonlyoncefromtheconstructoroftheclass.

Static :Valuecanbeinitializedonce.

40.Whatisaninterfaceclass?

Blockstatements
Declarationstatements
Expressionstatements
Selectionstatements
Iterationstatements
Jumpstatements
Trycatchstatements
Checkedandunchecked
Lockstatement

.co

39.WhatarethedifferenttypesofstatementssupportedinC#?

C#supportsseveraldifferentkindsofstatementsare

ar

Itisanabstractclasswithpublicabstractmethodsallofwhichmustbeimplementedinthe
inheritedclasses.
41.Whatarevaluetypesandreferencetypes?

er

ValuetypesarestoredintheStack.
Examples:bool,byte,chat,decimal,double,enum,float,int,long,sbyte,short,strut,uint,
ulong,ushort.
ReferencetypesarestoredintheHeap.
Examples:class,delegate,interface,object,string.
42.WhatisthedifferencebetweenstringkeywordandSystem.Stringclass?

re

StringkeywordisanaliasforSyste.Stringclass.Therefore,System.Stringandstring
keywordarethesame,andyoucanusewhichevernamingconventionyouprefer.The
Stringclassprovidesmanymethodsforsafelycreating,manipulating,and
comparingstrings.

Ca

43.WhatarethetwodatatypesavailableinC#?

Valuetype
Referencetype
44.WhatarethedifferenttypesofCaching?

TherearethreetypesofCaching:
OutputCaching:storestheresponsesfromanasp.netpage.
FragmentCaching:Onlycaches/storestheportionofpage(UserControl)

DataCaching:isProgrammaticwaytoCacheobjectsforperformance.
45.WhatisthedifferencebetweenCustomControlandUserControl?

CustomControlsarecompiledcode(Dlls),easiertouse,difficulttocreate,andcanbe
placedintoolbox.DragandDropcontrols.

.co

Attributescanbesetvisuallyatdesigntime.CanbeusedbyMultipleApplications(If
SharedDlls),EvenifPrivatecancopytobindirectoryofwebapplicationaddreference
anduse.Normallydesignedtoprovidecommonfunctionalityindependentof
consumingApplication.

UserControlsaresimilartothoseofASPincludefiles,easytocreate,cannotbeplacedin
thetoolboxanddraggeddroppedfromit.AUserControlissharedamongthesingle
applicationfiles.
46.Whatismethods?

Amethodisamemberthatimplementsacomputationoractionthatcanbeperformedby
anobjectorclass.Staticmethodsareaccessedthroughtheclass.Instancemethodsare
accessedthroughinstancesoftheclass.
47.Whatisfields?

48.Whatisevents?

ar

Afieldisavariablethatisassociatedwithaclassorwithaninstanceofaclass.

er

Aneventisamemberthatenablesaclassorobjecttoprovidenotifications.Aneventis
declaredlikeafieldexceptthatthedeclarationincludesaneventkeywordandthetype
mustbeadelegatetype.

re

49.Whatisliteralsandtheirtypes?

Literalsarevalueconstantsassignedtovariablesinaprogram.C#supportsseveraltypes
ofliteralsare

Ca

Integerliterals
Realliterals
Booleanliterals
Singlecharacterliterals
Stringliterals
Backslashcharacterliterals

50.Whatisthedifferencebetweenvaluetypeandreferencetype?

Valuetypesarestoredonthestackandwhenavalueofavariableisassignedtoanother
variable.
Referencetypesarestoredontheheap,andwhenanassignmentbetweentworeference
variablesoccurs.
51.Whatarethefeaturesofc#?

C#isasimpleandpowerfulprogramminglanguageforwritingenterpriseedition
applications.
ThisisahybridofC++andVB.ItretainsmanyC++featuresinthearea
statements,expressions,andoperatorsandincorporatedtheproductivityofVB.
C#helpsthedeveloperstoeasilybuildthewebservicesthatcanbeusedacrossthe
Internetthroughanylanguage,onanyplatform.

.co

C#helpsthedevelopersaccomplishingwithfewerlinesofcodethatwillleadtothefewer
errorsinthecode.
C#introducestheconsiderableimprovementandinnovationsinareassuchastype
safety,versioning.eventsandgarbagecollections.

52.Whatarethetypesoferrors?

Syntaxerror
Logicerror
Runtimeerror

53.Whatisthedifferencebetweenbreakandcontinuestatement?

ar

Thebreakstatementisusedtoterminatethecurrentenclosinglooporconditional
statementsinwhichitappears.Wehavealreadyusedthebreakstatementtocomeoutof
switchstatements.
Thecontinuestatementisusedtoalterthesequenceofexecution.Insteadofcomingout
ofthelooplikethebreakstatementdid,thecontinuestatementstopsthecurrentiteration
andsimplyreturnscontrolbacktothetopoftheloop.

er

54.Definenamespace?

Thenamespaceareknownascontainerswhichwillbeusedtoorganizethehierarchical
setof.Netclasses.

re

55.Whatisacodegroup?

Acodegroupisasetofassembliesthatshareasecuritycontext.
56.WhataresealedclassesinC#?

Ca

Thesealedmodifierisusedtopreventderivationfromaclass.Acompiletimeerroroccurs
ifasealedclassisspecifiedasthebaseclassofanotherclass.
57.Whatisthedifferencebetweenstaticandinstancemethods?
Amethoddeclaredwithastaticmodifierisastaticmethod.Astaticmethoddoesnot
operateonaspecificinstanceandcanonlyaccessstaticmembers.
Amethoddeclaredwithoutastaticmodifierisaninstancemethod.Aninstancemethod
operatesonaspecificinstanceandcanaccessbothstaticandinstancemembers.The
instanceonwhichaninstancemethodwasinvokedcanbeexplicitlyaccessedasthis.Itis
anerrortorefertothisinastaticmethod.

58.WhatarethedifferenttypesofvariablesinC#?

DifferenttypesofvariablesusedinC#are:

59.Whatismeantbymethodoverloading?

.co

staticvariables
instancevariable
valueparameters
referenceparameters
arrayelements
outputparameters
localvariables

Methodoverloadingpermitsmultiplemethodsinthesameclasstohavethesamename
aslongastheyhaveuniquesignatures.Whencompilinganinvocationofanoverloaded
method,thecompilerusesoverloadresolutiontodeterminethespecificmethodtoinvoke.

60.Whatisparameters?

ar

Parametersareusedtopassvaluesorvariablereferencestomethods.Theparametersof
amethodgettheiractualvaluesfromtheargumentsthatarespecifiedwhenthemethodis
invoked.Therearefourkindsofparameters:valueparameters,referenceparameters,
outputparameters,andparameterarrays.
61.IsC#isobjectoriented?

Yes,C#isanOOlangaugeinthetraditionofJavaandC++.

er

62.WhatisthedifferencebetweenArrayandArraylist?

Anarrayisacollectionofthesametype.Thesizeofthearrayisfixedinitsdeclaration.A
linkedlistissimilartoanarraybutitdoesnthavealimitedsize.

re

63.WhatarethespecialoperatorsinC#?

C#supportsthefollowingspecialoperators.

Ca

is(relationaloperator)
as(relationaloperator)
typeof(typeoperator)
sizeof(sizeoperator)
new(objectcreator)
.dot(memberaccessoperator)
checked(overflowchecking)
unchecked(preventionofoverflowchecking)
64.Whatismeantbyoperatorsinc#?
Anoperatorisamemberthatdefinesthemeaningofapplyingaparticularexpression
operatortoinstancesofaclass.Threekindsofoperatorscanbedefined:unaryoperators,
binaryoperators,andconversionoperators.Alloperatorsmustbedeclaredaspublic
andstatic.

65.Whatisaparameterizedtype?
Aparameterizedtypeisatypethatisparameterizedoveranothervalueortype.

66.Whatarethefeaturesofabstractclass?

Anabstractclasscannotbeinstantiated,anditisanerrortousethenewoperatoronan
abstractclass.

Anabstractclasscannotbescaled.
67.Whatistheuseofabstractkeyword?

.co

Anabstractclassispermitted(butnotrequired)tocontainabstractmethodsand
accessors.

Themodifierabstractisakeywordusedwithaclass,toindicatethatthisclasscannotitself
havedirectinstancesorobjects,anditisintendedtobeonlya'base'classtoother
classes.
68.Whatistheuseofgotostatement?

ar

ThegotostatementisalsoincludedintheC#language.Thisgotocanbeusedtojump
frominsidealooptooutside.Butjumpingfromoutsidetoinsidealoopisnotallowed.

er

69.Whatisthedifferencebetweenconsoleandwindowapplication?

Aconsoleapplication,whichisdesignedtorunatthecommandlinewithnouserinterface.
AWindowsapplication,whichisdesignedtorunonausersdesktopandhasauser
interface.

re

70.Whatistheuseofreturnstatement?

Thereturnstatementisassociatedwithprocedures(methodsorfunctions).Onexecuting
thereturnstatement,thesystempassesthecontrolfromthecalledproceduretothe
callingprocedure.Thisreturnstatementisusedfortwopurposes:
toreturnimmediatelytothecallerofthecurrentlyexecutedcode
toreturnsomevaluetothecallerofthecurrentlyexecutedcode.
71.WhatisthedifferencebetweenArrayandLinkedList?

Ca

Arrayisasimplesequenceofnumberswhicharenotconcernedabouteachothers
positions.theyareindependentofeachotherspositions.adding,removingormodifying
anyarrayelementisveryeasy.Comparedtoarrays,linkedlistisacomlicatedsequence
ofnumbers.
72.DoesC#haveathrowsclause?
No,unlikeJava,C#doesnotrequirethedevelopertospecifytheexceptionsthatamethod
canthrow.

73.DoesC#supportavariablenumberofarguments?

74.Canyouoverrideprivatevirtualmethods?
No,privatemethodsarenotaccessibleoutsidetheclass.

.co

75.Whatisamulticastdelegates?

Yes,uisngtheparamskeyword.Theargumentsarespecifiedasalistofargumentsofa
specifictype.

Eachdelegateobjectholdsreferencetoasinglemethod.However,itispossiblefora
delegateobjecttoholdreferencesofandinvokemultiplemethods.Suchdelegateobjects
arecalledmulticastdelegatesorcombinabledelegates.
76.WhichisanexclusivefeatureofC#?
Xmldocumentation.

77.IsusingofexceptionsinC#recommended?

Yes,exceptionsaretherecommendederrorhandlingmechanismin.NETFramework.

ar

78.Whatdoesabreakstatementdoinswitchstatements?

Thebreakstatementterminatestheloopinwhichitexists.Italsochangestheflowofthe
executionofaprogram.

er

Inswitchstatements,thebreakstatementisusedattheendofacasestatement.The
breakstatementismandatoryinC#anditavoidsthefallthroughofonecasestatementto
another.
79.IsC#objectoriented?

Yes,C#isanOOlanguageinthetraditionofjavaandC++.

re

80.Whatissmartnavigation?

Thecursorpositionismaintainedwhenthepagegetsrefreshedduetotheserverside
validationandthepagegetsrefreshed.
81.WhatisthedifferencebetweenCONSTandREADONLY?

Ca

Botharemeantforconstantvalues.Aconstfieldcanonlybeinitializedatthedeclaration
ofthefield.Areadonlyfieldcanbeinitializedeitheratthedeclarationor.
82.DoesC#haveathrowsclause?
No,unlikeJava,C#doesnotrequire(orevenallow)thedevelopertospecifythe
exceptionsthatamethodcanthrow.
83.Whatarethedifferentwaysamethodcanbeoverloaded?
Differentparameterdatatypes,differentnumberofparameters,differentorderof

parameters.
84.Doeventshavereturntype?

No,eventsdonothavereturntype.
85.Whatisevent?

Aneventisanactionperformedbasedonanothermethodoftheprogram.

.co

Aneventisadelegatetypedassmemberthatisusedbyanobjectoraclasstoprovidea
notificationtootherobjectsthataneventhasoccurred.
Aneventcanbedeclaredwiththehelpoftheeventkeyword.
86.Whatisanidentifier?

Identifiersarenothingbutnamesgiventovariousentitiesuniquelyidentifiedinaprogram.

87.WhatarethedifferenttypesofliteralsinC#?

Booleanliterals:TrueandFalseareliteralsoftheBooleantypethatmaptothetrueand
falsestate,respectively.

ar

Integerliterals:UsedtowritevaluesoftypesInt,ulnt,long,andulong.
Realliterals:Usedtowritevaluesoftypesfloat,double,anddedmal.
Characterliterals:Representsasinglecharacterandusuallyconsistsofacharacterin
quotes,suchas'a'.

er

Stringliterals:C#supportstwotypesofstringliterals,regularstringliteralandverbatim
stringliterals.Aregularstringliteralconsistsofzeroormorecharactersenclosedindouble
quotes,suchas"116110".Averbatimstringliteralconsistsofan@characterfollowed
byadoublequotecharacter,suchas"hello".

re

TheNullliteral:Representsthenulltype.

88.Whatismeantbydataencapsulation?

Ca

Dataencapsulation,alsoreferredtoasdatahiding,isthemechanismwherebythe
implementationdetailsofaclassarekepthiddenfromtheuser.Theusercanonlyperform
arestrictedsetofoperationsonthehiddenmembersoftheclassbyexecuting
specialfunctionscalledmethods.
89.Canyouoverrideprivatevirtualmethods?
No.Privatemethodsarenotaccessibleoutsidetheclass.
90.Whatisthemaindifferencebetweenasubprocedureandafunction?
Subproceduresdonotreturnavalue,whilefunctionsdo.
91.HowdoesC#differfromC++?


C#doesnotsupport#includestatement.Itusesonlyusingstatement.

C#doesnotsupportmultiplecodeinheritance.
CastinginC#ismuchsaferthaninc++.

.co

InC#switchcanalsobeusedonstringvalues.

InC#,classdefinitiondoesnotuseasemicolonattheend.

CommandlineparametersarraybehavedifferentlyinC#ascomparedtoC++.
92.Whatisnestedclass?

ANestedclassesareclasseswithinclasses.

Anestedclassisanyclasswhosedeclarationoccurswithinthebodyofanotherclassor
interface.

93.Canyouhaveparametersforstaticconstructors?
No,staticconstructorscannothaveparameters.

ar

94.IsStringisValueTypeorReferenceTypeinC#?
Stringisanobject(ReferenceType).

95.DoesC#providecopyconstructor?

er

No,C#doesnotprovidecopyconstructor.

96.Canaclassorastructhavemultipleconstructors?
Yes,aclassorastructcanhavemultipleconstructors.ConstructorsinC#canbe
overloaded.

re

97.Canyoucreateaninstanceofaninterface?
No,youcannotcreateaninstanceofaninterface.
98.CananInterfacecontainfields?

Ca

No,anInterfacecannotcontainfields.
99.Canaclasshavestaticconstructor?
Yes,aclasscanhavestaticconstructor.Staticconstructorsarecalledautomatically,
immediatelybeforeanystaticfieldsareaccessed,andaregenerallyusedtoinitializestatic
classmembers.Itiscalledautomaticallybeforethefirstinstanceiscreatedorany
staticmembersarereferenced.Staticconstructorsarecalledbeforeinstanceconstructors.
Anexampleisshownbelow.
100.WhatisthemainuseofdelegatesinC#?

Delegatesaremainlyusedtodefinecallbackmethods.

101.WhatisthedifferencebetweenShadowingandOverriding?

Overridingredefinesonlytheimplementationwhileshadowingredefinesthewhole
element.

102.Caneventshaveaccessmodifiers?

.co

Inoverridingderivedclassescanrefertheparentclasselementbyusing"ME"keyword,
butinshadowingyoucanaccessitby"MYBASE".

Yes,youcanhaveaccessmodifiersinevents.Youcanhaveeventswiththeprotected
keyword,whichwillbeaccessibleonlytoinheritedclasses.Youcanhaveprivateevents
onlyforobjectsinthatclass.
103.Whyisthevirtualkeywordusedincode?

TheVirtualkeywordisusedincodetodefinemethodsandthepropertiesthatcanbe
overriddeninderivedclasses.

ar

104.Whatareconstructorsanddestructors?

Constructorsanddestructorsarespecialmethods.

Constructorsanddestructorsarespecialmethodsofeveryclass.
Eachclasshasitsownconstructoranddestructorandarecalledautomaticallywhenthe
instanceofaclassiscreatedordestroyed.

er

Theconstructorinitializesallclassmemberswheneveryouaccesstheclassandthe
destructordestroysthemwhentheobjectsarenotrequiredanymore.
105.Howcanwesuppressafinalizemethod?

re

GC.SuppressFinalize()

106.DoesC#supportavariablenumberofarguments?

Yes,usingtheparamskeyword.

Ca

Theargumentsarespecifiedasalistofargumentsofaspecifictype,e.g.,int.Forultimate
flexibility,thetypecanbeobject.
Thestandardexampleofamethodwhichusesthisapproachis
System.console.writeLine().
107.Whichmethodwillyoucalltostartathread?
Start

108.WhatisGeneric?

Generichelpustocreateflexiblestrongtypecollection.

109.Whatarethedifferenttypesofpolymorphism?

Therearetwotypesofpolymorphism.Theyare:

.co

CompiletimePolymorphism
RuntimePolymorphism

Genericbasicallyseperatethelogicfromthedatatypeinordermaintainbetterreusability,
bettermaintainabilityetc.

110.Whatisthedifferencebetweencompiletimepolymorphismandruntime
polymorphism?

CompiletimePolymorphism
CompiletimePolymorphismalsoknownasmethodoverloading.

RuntimePolymorphism

Methodoverloadingmeanshavingtwoormoremethodswiththesamenamebutwith
differentsignatures.

ar

RuntimePolymorphismalsoknownasmethodoverriding.

Methodoverridingmeanshavingtwoormoremethodswiththesamename,same
signaturebutwithdifferentimplementation.
111.WhichnamespaceenablesmultithreadedprogramminginXML?

er

System.Threading

112.Canwedeclareablockasstaticinc#?

No,becausec#doesnotsupportstaticblock,butitsupportsstaticmethod.

re

113.Canwedeclareamethodassealed?

InC#amethodcan'tbedeclaredassealed.Howeverwhenweoverrideamethodina
derivedclass,wecandeclaretheoverriddenmethodassealed.Bydeclaringitassealed,
wecanavoidfurtheroverridingofthismethod.

Ca

114.WhatCommandisusedtoimplementpropertiesinC#?
get&setaccessmodifiersareusedtoimplementpropertiesinc#.
115.Whatisstaticmember?
Thememberdefinedasstaticwhichcanbeinvokeddirectlyfromtheclasslevel,rather
thanfromitsinstance.
116.WhatisthesyntaxtoinheritfromaclassinC#?

Whenaclassisderivedfromanotherclass,thenthemembersofthebaseclassbecome
themembersofthederivedclass.

Theaccessmodifierusedwhileaccessingmembersofthebaseclassspecifiestheaccess
statusofthebaseclassmembersinsidethederivedclass.
ThesyntaxtoinheritaclassfromanotherclassInC#isasfollows:
classMyNewClass:MyBaseClass

.co

117.WhatisabasicdifferencebetweenthewhileloopanddowhileloopinC#?

Thewhilelooptestsitsconditionatthebeginning,whichmeansthattheenclosedsetof
statementsrunforzeroormorenumberoftimesiftheconditionevaluatestotrue.Thedo
whileloopiteratesasetofstatementsatleastonceandthencheckstheconditionat
theend.
118.Whatisthemaindifferencebetweenasubprocedureandafunction?

Subproceduresdonotreturnavalue,whilefunctionsdo.

119.Whataresealedclassesinc#?

Thesealedmodifierisusedtopreventderivationfromaclass.

ar

Acompiletimeerroroccursifasealedclassisspecifiedasthebaseclassofanother
class.

er

120.WhatisthedifferencebetweenclassandanInterface?

Abstractclassescanhaveimplementationsforsomeofitsmembers,buttheinterface
can'thaveimplementationforanyofitsmembers.
Interfacescannothavefieldswhereasanabstractclasscanhavefields.

re

Aninterfacecaninheritfromanotherinterfaceonlyandcannotinheritfromanabstract
class,whereasanabstractclasscaninheritfromanotherabstractclassoranother
interface.
Aclasscaninheritfrommultipleinterfacesatthesametime,whereasaclasscannot
inheritfrommultipleclassesatthesametime.

Ca

Abstractclassmemberscanhaveaccessmodifierswhereasinterfacememberscannot
haveaccessmodifiers.
121.Whatisthedifferencebetweenanabstractmethod&virtualmethod?
AnAbstractmethoddoesnotprovideanimplementationandforcesoverridingtothe
derivingclass(unlessthederivingclassalsoanabstractclass),whereasthevirtual
methodhasanimplementationandleavesanoptiontooverrideitinthederivingclass.
ThusVirtualmethodhasanimplementation&providesthederivedclasswiththeoptionof
overridingit.Abstractmethoddoesnotprovideanimplementation&forcesthederived
classtooverridethemethod.

122.WhatisStaticMethod?
ItispossibletodeclareamethodasStaticprovidedthattheydon'tattempttoaccessany
instancedataorotherinstancemethods.

123.WhatisaNewmodifier?

Thenewmodifierhidesamemberofthebaseclass.C#supportsonlyhidebysignature.

.co

124.WhataretheadvantagesofgetandsetpropertiesinC#?

Thegetpropertyaccessorisusedtoreturnthepropertyvalue.
Thesetpropertyaccessorisusedtoassignanewvalue.

125.Whatarethedifferencebetweenconstandreadonly?

Aconstcannotbestatic,whilereadonlycanbestatic.

Aconstneedtobedeclaredandinitializedatdeclarationonly,whileareadonlycanbe
initializedatdeclarationorbythecodeintheconstructor.

Ca

re

er

ar

Aconst'svalueisevaluatedatdesigntime,whileareadonly'svalueisevaluatedat
runtime.

Вам также может понравиться