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

C#.NET/VB.

NET interview questions


Explain the elements of the .NET Framework. a. CLR (Common Language Runtime): It is a common managed environment where all the .net programs run. Supports multiple languages and has the garbage collector. .Net Framewor Class Libraries: For each source code compiler (!".N#$% C&.N#$% etc.)% there is a minimum set o' coding standards that must be met. $he minimum set o' coding standards that must be met to compile .N#$ code into (SIL code is nown as CLS ) Common Language Speci'ication. $he role o' the Common Language Speci'ication is to ensure that all generated code ((SIL) that meets the minimum set o' coding standards can operate success'ull* within the .N#$ 'ramewor . $+# C$S (Common $*pe S*stem) handles conversion o' programming)language data t*pes into .N#$ compatible ((SIL) data t*pes. $he implicit bene'it o' the C$S is the reduction o' development time when attempting to coordinate data t*pes between two sets o' di''erent programming)language code. ,ata and -(L: Support 'or disconnected programming model and -(L. -(L webservices: creating webservices 'or distributed architecture. .eb'orms: /rovides support and 'unctionalit* 'or .eb based 0I. .indows 'orms: /rovides support and 'unctionalit* 'or .indows based 0I.

b.

c. d. e. '.

What is assem l! manifest" What is the information it provi#es. 1ssembl* (ani'est is a 'ile that contains data that describes how the elements present inside an assembl* are connected to each other. $he assembl* mani'est contains assembl* metadata to de'ine the scope o' the assembl* and resolve re'erences to resources and classes. In'ormation provided b* 1ssembl* (ani'est: a. 1ssembl* Name b. !ersion Number c. Culture d. Strong name e. List o' 'iles inside the assembl* f. Re'erence in'ormation Explain how a .NET appli$ation is $ompile# an# exe$ute# 1n* code written in an* .N#$ complaint languages when compiled% converts into (SIL ((icroso't Intermediate Language) code in 'orm o' an assembl* through CLS% C$S. IL is the language that CLR can understand. 2n e3ecution% this IL is converted into binar* code b* CLR4s 5ust in time compiler (6I$) and these assemblies or ,LL are loaded into the memor*.

%es$ri e the .NET ase $lass li rar! .N#$4s "ase class librar* e3ists in order to encapsulate huge number o' common 'unctions and ma es them easil* accessible to the developer. .N#$ base class librar* provides the 'unctionalit* li e 1,2.N#$% -(L% $hreading% I2% Securit*% ,iagnostics% Resources% 7lobali8ation% collections etc. It serves as the main point o' interaction between developer and runtime. Explain the #ifferen$e etween value t!pes an# referen$e t!pes

!alue $*pe: a. Stores the data. b. $he value o' value t*pes is stored on the managed stac . c. 2ne variable can have 5ust one value. d. $he* are lighter ob5ects. Re'erence $*pe: a. Stores the re'erence to the data. b. 1 re'erence t*pe is allocated on the heap. c. several variables can re'erence the same data d. $he* are heavier ob5ects. Explain the importan$e of &mports an# 'sin( )tatements. Import statement: creates a propert* on the global ob5ect with the name supplied as namespace and initiali8es it to contain the ob5ect that corresponds to the namespace being imported. 1n* properties created using the import statement cannot be assigned to% deleted% or enumerated. 1ll import statements are e3ecuted when a script starts. 0sing statements: mainl* de'ines the namespaces whose ob5ects will be used in the 'orm. $his clearl* solves 9 purposes: ,e'ines all the namespaces that will be used in a 'orm. Secondl*% reduces the hassle 'or the programmer to t*pe the name o' namespace again and again while using classes:ob5ects that belong to the namespace. Explain the #ifferen$e etween a $lass an# a stru$ture

Class: a. It is re'erence t*pe. b. Null value can be assigned to a variable in a class c. It can have destructor. d. 1ll variables in classes are b* de'ault private. e. 7ood to be used 'rom architecture view as it provides high 'le3ibilit*. )tru$ture: a. It is value t*pe. b. Null value assignment is not 'easible here. c. Cannot have destructor. d. 1ll variables in structures are public. e. 7ood to be used 'or simple data structures.

Explain how (ar a(e $olle$tion mana(es the re$lamation of unuse# memor!. $he garbage collector assumes that all ob5ects in the managed heap are garbage. It starts wal ing the roots and builds a graph o' all ob5ects reachable 'rom the roots recursivel*. It stops when it attempts to add an ob5ect to the graph that it previousl* added. $he graph contains the set o' all ob5ects that are reachable 'rom the application;s roots. 1n* ob5ect:s that is not in the graph is not accessible b* the application% and is considered garbage. Collection onl* occurs when the heap is 'ull. In such a case% each and ever* garbage ob5ect calls the Finali8e method and reclaims the unused memor*. <<. #3plain how garbage collection deals with circular re'erences. Explain how (ar a(e $olle$tion #eals with $ir$ular referen$es. $he .Net runtime nows about all the re'erences between the ob5ects. It can identi'* all the circular re'erences that are reachable 'rom the root and hence 'inali8e them to 'ree them all at once i' and when needed. Explain the pro$ess of $reatin( a menu usin( the *ain*enu $omponent. (ain(enu component is a component that allows the displa* o' (enus at runtime on a 'orm. /rocess o' creating (enu using (ain(enu Component: a. 1dd (ain(enu component on .indows Form. b. (enu designer allows deciding the structure o' the main menu b* selecting the $*pe +ere area and adding the (enu Items to be displa*ed on the menu. c. 1dd 'unctionalit* to (enu Items as re=uired. Explain the pro$ess of $reatin( a $ontext menu usin( the Context*enu $omponent Conte3t(enu component provides the users with the abilit* to access some ver* 're=uentl* used commands. Conte3t menu wor s b* right clic o' mouse. $he* mainl* provide access to commands particular to the control that has been clic ed upon. +ro$ess for $reatin( $ontext menus, a. 2pen the windows 'orm application. b. Select Conte3t(enu component 'rom toolbo3. c. 1 menu is added. Clic on $*pe here and t*pe in new (enu Items to be placed on the (enu. d. /rovide the 'unctionalit*. e. 1ssociate the conte3t menu with the 'orm or the control it is supposed to be related to. What is a #ele(ate" Explain how to $reate it. 1 delegate declares a re' t*pe that re'erences a named o' anon*mous method. ,elegates are secure and t*pe)sa'e. Consider them as t*pe sa'e 'unction pointers. public delegate void ,el>$?($ item)@

,el>int? dA B new ,el>int?(Noti'*)@ Explain how to #e$lare an# raise events from !our appli$ation. ,eclare #vents: C#ventD e*word is used to declare an event. public delegate void (*Custom+andler(ob5ect o% (*#vent1rgse)@ public class (*#vent1rgs: #vent1rgs E public readonl* int 1ge@ public (*#vent1rgs(int age) E 1ge B age@ F F public class (*CustomListener E public void Show(ob5ect o% (*#vent1rgs e) E Console..riteLine( G1ge is EHFG% e.1ge)@ F F %es$ri e how to implement event han#lers an# asso$iate them with events. public class (*Class E public static event (*Custom+andler (*#vent@ public static void (ain() E (*CustomListener mcll B new (*CustomListener()@ (*#vent IB new (*Custom+andler(mclA.Show)@ 7et1ge()@ F public static void 2n(*#vent((*#vent1rgse) E i'((*#ventJBnull) (*#vent(new ob5ect()%e)@ F public static void 7et1ge() E (*#vent1rgseA B new (*#vent1rgs(9<)@

2n(*#vent(eA)@ F F What is Break *o#e" -ow to set reakpoints"

"rea mode is the state o' an application when the e3ecution gets paused and allows the developer to edit the value in the current state. $o attain a brea mode we can do an* o' the 'ollowing steps: a. Selecting "rea 'rom the Run menu (CtrlI"rea ) or pressing the pause button. b. Reaching to brea point. Setting up the brea points: a. 7o to the line where *ou need to mar the brea point. b. Clic with mouse on le't corner margin o' that line. c. 1nother wa* is to press FK %es$ri e how to step throu(h $o#e in .NET. Steps to step through the code in .N#$: a. Start the program in debug mode. b. .hen the 'irst brea point is reached then step through can be done in one o' the two wa*s: i. /ress FAH to move to ne3t line. ii. Select debug menu and clic on step over. $his would step over the brea point to ne3t level. c. 2ther options are: C)tep &ntoD and C)tep .utD. %es$ri e the #e u((in( win#ows availa le in .NET. ,ebug)?.indows: "rea points: displa*s a list o' all the brea points and where the* are. Shows condition when that brea point will be hit i' a condition e3ists and the +it Count shows the number o' times that brea point has been hit. 2utput: ,ispla*s the status messages 'or various 'eatures in the I,#. It shows the output 'orm a list o' ob5ects throughout debug mode o' the application. Immediate: $his window allows the programmer to write code and veri'* values through programming while debugging the application. It helps in chec ing the values o' ob5ects:controls etc% and the conditions throughout the application in debug mode. .hat are ,ebug and $race classesL #3plain how to use them to displa* error classes. "oth are used to help programmers 'ind errors% occurring events and 'low o' code. In release mode% however% debug class is disabled and onl* $race class is valid to trap things in a live application. "oth have assert 'unctions to validate values.

$race..riteLine(variable value or comment). ,ebug..riteLine(variable value or comment). .e could create error handlers to trap unhandled e3ceptions trapped b* $race and ,ebug class. %es$ri e how to $reate Tra$e /isteners an# lo( Tra$e output. MConditional(G$R1C#G)N public static void Initiali8e0nhandled#3ception+andler() E 1pp,omain.Current,omain.0nhandled#3ception IB new 0nhandled#3ception#vent+andler(Cutom#3ception+andler)@ F public static void Custom#3ception+andler(ob5ect sender% 0nhandled#3ception#vent1rgs args) E #3ception eB(#3ception) args.#3ception2b5ect@ $race..riteLine(G#3ception: GIe.(essageIGOnGIe.7et$*pe() I GOnStac $race:OnGIe.Stac $race)@ (essage"o3.Show( G1n error has occurred:GIe.(essageIGOnin: GIe.7et$*pe()% GFatalG% (essage"o3"uttons.2P% (essage"o3Icon.Stop% (essage"o3,e'ault"utton."uttonA)@ $race.Close()@ /rocess.7etCurrent/rocess().Pill()@ F MConditional(G,#"07G)N public static void $rap,ebug(string str) E ,ebug..riteLine(G,ebug error: GIstr)@ F What are Tra$e swit$hes" %es$ri e how to $reate an# use Tra$e swit$hes. $race switches allow us to 'ilter% enable:disable the outputs through $race. .e can con'igure them through the con'ig 'ile. Q t*pes o' trace switches: "ooleanSwitch: #nable:,isable trace statements. $raceSwitch and SourceSwitch: used 'or trapping particular $race levels. "ooleanSwitch dataSwitch B new "ooleanSwitch(GCommentG% GmoduleAG)@ $raceSwitch generalSwitch B new $raceSwitch(GcommentG% GmoduleAG)@ Explain how to $onfi(ure Tra$e swit$hes in the appli$ation0s .$onfi( file. switches are con'igured using the .con'ig 'ile

>s*stem.diagnostics? >switches? >add nameBG(*$raceSwitchG valueBGAG :? >add nameBG$raceSwitch9G valueBGAG :? >:switches? >:s*stem.diagnostics? both are on. Explain how ex$eptions are han#le# ! the $ommon lan(ua(e runtime in .NET.

$he CLR uses a techni=ue generall* re'erred to as a two)pass e3ception review process. .hat this means is that the CLR will process an e3ception in two passes. In the 'irst pass% the CLR will determine i' there is a handler 'or the e3ception. $his is done b* reviewing the entries in the S#+ table@ speci'icall* it loo s at the $r* 2''set and $r* Length 'lags to see i' the e3ception occurred within a guarded bloc % and i' so% whether the Flags entr* dictates that a handler e3ists 'or this t*pe o' occurrence. Let;s assume that the CLR did 'ind a handler during the 'irst pass. 1t that point the CLR begins a second pass o' the S#+ table during which it will wor through the e3ecution phase o' the e3ception management process. So we can divide the two passes into a discover* pass% in which we determine whether there is a handler in this method conte3t to handle the e3ception@ and an e3ecution pass% in which we actuall* e3ecute the handler and an* special rules. .hen code throws an e3ception% the CLR loo s up the call stac loo ing 'or a catch 'ilter to handle the e3ception. .hen it 'inds the relevant catch bloc % be'ore e3ecuting the code% it will e3ecute all code in all 'inall* bloc s ) starting 'rom the tr* bloc that threw the e3ception and stopping with the catch 'ilter that matches the e3ception. when the CLR encounters an e3ception 'or a method it will use the descriptors in the S#+ table to determine how to handle the e3ception% which code bloc is a''ected% and what handler should be invo ed. %es$ri e the #ifferent t!pes of user1authore# $ontrols in NET. 0ser authored controls are which not part o' the .net 'ramewor librar*. It includes both custom controls and user controls. a. Custom Controls, $he* loo similar to 1S/.N#$ controls. $he* can be created in one o' the Q wa*s:) a. ,eriving a custom control 'rom e3isting custom control. b. (a ing a composite custom control b* combining 9 or more e3isting controls c. "* creating a new control 'rom scratch b* deriving the control 'rom its base class. b. 'ser Controls, enables a part o' 1S/.N#$ page to be reused. $he reusable part is in 'orm o' a control with the e3tension .asc3. $he* loo li e to be a group o' 1S/.N#$ controls which can be used over and over again.

Explain with $o#e sample how to $reate an inherite# $ontrol. Steps to create inherited Control:) a. Create a new pro5ect. b. 1dd a custom control to the pro5ect.

c. Change the name o' the class *ou need to inherit the control 'rom the base class. #.g. inherit the class 'rom S*stem..indows.Forms."utton i' the control s to be inherited 'rom a button class. d. Implement the control with custom properties and 'eatured needed b* the control. e. 2verride the 2n/aint method i' the control4s appearance needs to be changed. '. Save the build the control g. Re'erence *ou control into another or the same pro5ect and use the control. Explain with $o#e sample how to $reate a user $ontrol. )teps a. b. c. d. to $reate a 'ser $ontrol, Select a pro5ect Right clic and add a new item (0ser Control ) .asc3) to the selected pro5ect. 1dd RControl ,irective 1dd all the controls that *ou want to be displa*ed on the 0ser control as a part o' one or more web pages. e. .rite the code 'or all the tas s to be per'ormed b* the user control. '. Create accessor methods 'or the outside world accessing this user control.

'sin( the 'ser $ontrol, a. Register the control on the webpage it needs to be used b* putting RRegister directive. b. Speci'* the 'ollowing attributes to the register directive: a. $ag/re'i3: de'ines the namespace in which the control would reside b. $agName: de'ines the name with which control is re'erred c. Src: /ath o' where the control is ept. c. Control is then used on the page using the 'ollowing code: >$ag/re'i3:$agName :? Explain with $o#e sample how to $reate a $ustom $ontrol. Steps to create a custom control: a. Create a new pro5ect. b. 1dd a custom control to the pro5ect. c. Change the name o' the class *ou need to inherit the control 'rom the base class. #.g. inherit the class 'rom S*stem..indows.Forms."utton i' the control s to be inherited 'rom a button class. d. Implement the control with custom properties and 'eatured needed b* the control. e. 2verride the 2n/aint method i' the control4s appearance needs to be changed. f. Save the build the control g. Re'erence *ou control into another or the same pro5ect and use the control. %es$ri e the .NET Framework ar$hite$ture. .Net 'ramewor has two components: 1. .Net 'ramewor class librar* 2. Common language runtime. FCL 'acilitates the t*pes through C$S which are common to all the supported languages. $he CLS ensures that all languages are interoperable. $his ensures that all code is managed .i.e. code which is converted to (SIL.

$he CLR has the class loader that load the (SIL code o' an application into runtime% which is then converted into native code b* the 6I$ complier. $he CLR manages code and provide services such as memor* management% threading% remoting% t*pe sa'et*% securit*% #3ception handling etc. What is the mana(e# exe$ution pro$ess" (anaged e3ecution process is a process where CLR e3ecutes the managed code. $he steps involved in this process are: a. Choosing the right compiler b. Compiling the code to (SIL. $his also generates the re=uired metadata. c. Compile the (SIL ode to native machine code. d. #3ecuting the code with the variet* o' services available. What are assem lies" %es$ri e the t!pes of assem lies. 1ssembl* is a compiled output o' program which are used 'or eas* deplo*ment o' an application. $he* are e3ecutables in the 'orm o' e3e or dll. It also is a collection o' resources that were used while building the application and is responsible 'or all the logical 'unctioning. T!pes of assem lies, a. /rivate 1ssemblies: are accessible b* a single application. $he* reside within the application 'older and are uni=ue b* name. $he* can be directl* used b* cop*ing and pasting them to the bin 'older. b. Shared 1ssemblies: are shared between multiple applications to ensure reusabilit*. $he* are placed in 71C. c. Satellite 1ssemblies: are the assemblies to provide the support 'or multiple languages based on di''erent cultures. $hese are ept in di''erent modules based on the di''erent categories available. Explain the role of assem lies in .NET. 1ssemblies are main building bloc s. 1n assembl* ma*be de'ined as a unit o' deplo*ment. 1 single assembl* is a collection o' t*pes% and resources. $he CLR does not understand an* t*pes that are outside assemblies. $he CLR e3ecutes the code in assemblies as the* contain (SIL code. $he* de'ine t*pe% version and securit* boundaries. 1ssemblies in .Net are a solution to the ,ll hell problem as one can use di''erent versions o' same assembl* in di''erent applications at the same time. $o ma e a shared assembl*% we need to register it with 71C where as private assemblies reside in applications director*. What are win#ows servi$es" -ow are the! #iffer from other .NET appli$ation" .indows services are a wa* to create continuousl* running applications in the bac ground. $he* don4t inter'ere with other applications and can be run whenever a machine starts. $he* can be paused i' and when needed and =uietl* run in the bac ground without the need o' an* user intervention. .indows services can be con'igured to run under speci'ic user accounts. $he* run under their own windows sessions and are ideal 'or tas s that need to be per'ormed periodicall* or 'or monitoring re=uirements. (ain di''erence between windows services and other .Net applications lies in the 'act that the* run in their own windows session without an* user intervention in the bac ground.

For more questions with answers2 follow the link

elow,

http:::www.careerride.com:CSharp)Interview)Suestions.asp3
.e do not warrant the correctness o' content. $he ris 'rom using it lies entirel* with the user. .hile using this document% *ou agree to have read and accepted the terms o' use and privac* polic*.

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