.net Interview Questions

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View .net Interview Questions as PDF for free.

More details

  • Words: 4,288
  • Pages: 15
1) CLR: Common language runtime Used for: Type checking----------------------to see if valid operations are being performed) Garbage Collector------------------Automatic memory management Class loader-----------------------Loads classes into runtime MSIL to native code compiler-------converts msil to native code Security Engine--------------------enforces security Thread Support---------------------Multithreading support Exception Manager------------------has mechanism to handle run time exceptions Debug Engine-----------------------allows to debug diff applications Com Marshaler----------------------Exchange data between .net appliactions and com environment

2) Private Assembly: Installed in the web application folder. Used by only one application. 3) Shared Assembly: Installed in Global Assembly Cache(GAC)----using gacUtil.exe Shared by many applications To be installed in GAC the assembly must be strong named------using sn.exe----provides a public and a private key for assembly The key file must be specified in Assembly with AssemblyKeyFileAttribute

4) Enable Postback: All server controls have this property--------that is to say that the form should be posted back to the server to process any requests

1

Html controls by default don't have this-------but can be made to be posted back by putting "runat=server" with their declaration 5) Side by side execution: Assemblies help in side-by-side execution. Each assembly has 1) Assembly metadata-----------------contains info about assembly version (number, build number, revision number, security id, resources required and scope of assembly) which is used by CLR to make a decision of which assembly to run. 2) Type Metadata 3) MSIL code----------------without assembly metadata msil code cannot be loaded and executed by CLR 4) Resources 6) Assemblies r two types: 1)Static 2)Dynamic 1) Static-------------1) It is contained in a portable executable. (Which can be dll or exe) it contains information about types, interfaces and resources. ------------------------2) They r stored on the hard disk ------------------------3)It is created when you compile the program using any .net compilers. 2)Dynamic-----------1)No portability. ------------------------2) not stored on HD ------------------------3) Created during runtime when the application requires types from these assemblies. ------------------------4) System.Reflection.Emit namespaces used in the dynamic creation of assemblies.

7) IsPostBack Method: Used for: It is used when you want to know if the form is posted back for the first time or not. Helpful in: When you have more data and don't want to do some coding or loading of data every time the form is posted back. 8) Difference between Array and ArrayList: Array is used to store only one kind of Data ArrayList is used to store Different kinds of data or objects.

2

9) EventHandlers: These are to handle any events from the web form. Events r to notify some method or object that something has happened. Events use Delegates to send this notification to receiving methods as they don't know which method will receive. Delegate’s r used to store method references in them so that they can call those methods. The methods which r called must have same signature as delegate (Signature--------return type, parametrs type) . Instance methods referred by delegates contain---------Method entry point reference and reference to object. Static methods referred by delegates contain------------Method entry point reference only. Any event which is posted by the form can be handled both by sever and client. For a server control to handle the client event even before server side code you should add an attribute for it. 10) Difference between Dataset and DataReader 1) DataSet is disconnected---only connects to database when updating or getting information from database -------- DataReader-----Connected to a Database all the time. 2) DataSet ----- U can do any updates or any modification to database using dataset DataReader ----- is read only 3) Performance: DataReader is better than DataSet Reason:---------DataReader is forward only, fast and read only. Must close the DataReader. Usage depends on how u wants the data to be 1) For example if u have millions of rows of data and want to use it and it is just static (No change) then u must use DataReader----------as it is just to read data DataSet can not be used as it loads all the data into memory which is not very efficient in this case. 11) DataAdapter(da): 1) When u use da u don't have to open connection to database explicitly. U fills the data into dataset using da. 12) DataGrid (dg): 1) For paging (its like when u have more data and it is displayed on multiple pages and u want pages to be displayed) dg is the better option. 2) You bind the data to dg.

3

3)You can use BoundColumn property of dg to make any column readonly.---like when u want user to update using dg but don't want him to change any primary key column

13) SqlCommand -------U has to explicitly open the connection to database when u uses command. -Error otherwise

s14) Overloading (OL) Overriding (OR) --------------------------------------------------------------------------1) Giving same name to methods but 1) Giving same name to many methods with different signature with same signature (parameters, return type) 2)There can be multiple methods of 2)Only one method can be overrided in this type in a single class a class 3)Just changing the return type of method does not mean OL 15) Validation: For example if u have two text boxes with name and password---------and there r two required filed validators on those(to see if user has entered any info) and if u leave the two blank and send click send button then the form will not be posted back. U can put some value in Initial value property of Required field validator to check if user has changed that value or not. When user doesn't change a validation will be raised. The only validation control for which you don't have to specify any control to validate is Custom validate control. 16) Differences between Asp and Asp.net 1)asp--------code was interpreted asp.net------code is compiled so better performance 2)asp--------few server controls asp.net------server controls like datagrid, validation controls,list boxes 3)asp---used ado asp.net-ado.net

4

17) How can you isolate a project that is running on the same web server as other projects? The project is a must. Basically u have three kinds of processing env to run .net applications. 1) Within IIS inetinfo.exe------which can effect iis as it is in the same process 2)pooled with other applications in dllhost.exe-----default. even if any damage can affect any process but not inetinfo.exe 3)separate dllhost.exe---------no affect on any process Performance wise: 1)within---------------better cuz all calls r in process 2)pooled---------------not better than 1 3)isolated-------------very poor since all calls r out of process u can isolate that project with this or else you have isolate in IIS properties which helps in doing this. When you check this and restart the server it will actually load that project into MTS explorer so MTS takes care of any damages. 18) How can you say that a control like checkbox or anything when checked that it refers to that particular form or id of employee or anything U can provide the control with id, which in turn can be checked. 19) Webservices def ---------------XML Web services are applications that provide the ability to exchange messages in a loosely coupled environment using standard protocols such as HTTP, XML, XSD, SOAP, and WSDL. XML Web service enables the building of modular applications within and across companies in heterogeneous environments making them interoperable with a broad variety of implementations, platforms and devices. 20) When you overload methods in web services, is there any mechanism to differentiate between them using soap. U can specify MessageName attribute, which will be used by soap. 21) Other general possible questions related to ur resume 1)What was the project that u worked on recently 2)Explain it 3)What role did you play in it 4)What r the main components that u were working on 5)were you there from beginning to the end of project 6)what kind of problem did you face during those project development related to the components and techniques u have used 7)How did you resolve those problems

5

22) Two disadvantages by calling COM components from web services 1) have to marshal the data between com and .net that is performance degradance. 2) 23) what r static constructors Static constructors r used in initializing the class itself. They r executed when the class loads for the first time. They cannot have any parameters. 24) What is the best class to use for string related operations in Asp.net and what is the difference between using this and other classes U can use StringBuilder for better performance. When u add two strings with +(s1+s2) the actual thing that happens inside is that those two string r destroyed (as string are immutable)and a new string which contains both contents of those string will be created. It is time consuming since there is a creation of object involved where with stringbuilder this is not the case. 25) what is Stackalloc Allocates a block of memory on the stack. the address of the block is stored in pointer ptr. This memory is not subject to garbage collection and therefore does not have to be pinned (via fixed). The lifetime of the memory block is limited to the lifetime of the method in which it is defined. 26) explain why we use exception handling To catch any unknown exception or any exceptions that might cause the program to end abnormally. 27) How do you configure security in asp.net Using Web.Config authentication section…mode=”forms/windows/passport” 28) Can you import code from vb.net Yes 29) what is the benefit of it Vb is better for developing UserInterface and besides any previously coded code can be used as both of them have CLS (common language specification) 30) How many cluster indexed can we have on a table Only one. 31) How does a cluster index store keys It actually stores the data physically. It uses BTrees in this process. So if you have clustered indexes then even if you have other non clustered indexes the data will be stored according to clustered index.

6

32) Can we make a stored procedure run everytime we call it…lets say in an env where the data chages always. Yes, you can…Using With Recompile option in the creation of the stored procedure. 33) What namespace do you use for exceptions in asp.net? System.Exception 34) How do you handle exception in asp Using AspError object 35) Can we have multiple catch blocks for one try block/Flow of Exception block Yes …we can…if you specify a particular catch block which contains info about the exception then that will be executed. If not the most general catch block will be executed. Any how the finally block will be executed all the time. Try…specific exception---if not general exception---finally 36) How many authentication types r there in asp.net 3---forms,passport and windows…you specify this info in web.config 37) What is a user control User control is something that combines two or more controls to give them a single visual appearance. And it is reusable. So, for example if u need to ask the user to enter address details then u have to put all the controls like name,city,zip and all of those on every form where u need it and code it. But instead what if u have something which will have all this functionality combined in one control and the only thing u have to do then is just to drag it from the toolbox and drop it where it is needed. U r not only combining more controls into one but u r also having the necessary functionality wherever u need. 38) Can you store info about server control and how Yes…Using Viewstate u can store info…Viewstate hashes the info, which prevents any corruption to the data, and this data can be retrieved when webform Is posted back to get info about controls. 39) Difference between server.transfer and server.execute Server.Transfer transfers some info to the other web form and beside it gives the executing capability to that webform. Server.Execute doesn’t give executing capability to the other web form. 40) What is ExecuteScalar and how does it work You can update data in database directly without using DataAdapter using Executescalar, ExecuteNonQuery and ExecuteReader. ExecuteScalar returns a single value such as a count of employees or so. Even if u get multiple values from database it will return only the first row first column value.

7

41) How does Machine.config defer from Web.config Any changes in Machine.config effect all the applications running on that machine where as any changes to web.config affect only a particular application. However web.config overrides any settings in machine.config. 42) What if there is static data and you want better performance. U can take that info into a cache object and use it. 43) What is impersonation? What is the default account that is used by IIS? Providing an unknown user with some kind of identification or account is called impersonation. Default---IUSER_machine 44) Why do you need Passport authentication? When you don’t want user to remember all the user names and password for all the sites that u r hosting u need passport authentication. It will store a profile for the user and helps user in using only one username/password to enter all the sites. 45) What is the deference between GenericPrincipal and WindowsPrincipal Generic principal contains null info about the role of the user Windowsprincipal contains Windows role of the user. 46) What information does satellite assemblies contain/how do they defer from main assemblies. Satellite assemblies contain only resources where as main assembly contains assembly manifest---version info,security, MSIL code and type metadata. U use al.exe to make assemblies from resource files. 47) What is the tool used to give strong name to assembly? Sn.exe---if u want to delay the key file adding to assembly you can specify –delay in that. 48) How do you install assembly in GAC? Using GacUtil.exe 49) How do you make a method accessible/ to be called by clients in Web services Using WebMethod attribute 50) How can u access or modify any info coming from the client in web services U have to create a class which inherits from SoapExtension or implements IHttpHandler to get information from client and you can do like---checking for security in there. But u should however have to create a new object, which references that info.

8

51) How do you create custom exception classes in asp.net Using System.ApplicationException…u should inherit from this class to create custom exception classes. 52) How does runtime know which class/object to load to use? It refers to assembly which has assembly manifest---info about the assembly version, type metadata and MSIL code to load the class and the data and to compile the MSIL to native code 53) How many parameters r there in C# 4 kinds of parameters: 1)out--------for output----------change in original value as ref is passed 2)value-------for in parameters----no change in original value since value is passed 3)ref---------for ref--------change in original value as reference is passed 4)params------when u want to send multiple values but to have a single object to hold all of them-----it must be the right most parameter in the parameter list and there should be only one params parameter for a method. 54) What is the difference between ref parameter and out parameter Ref parameter should be initialized in the method, which sends it as a parameter Out parameter doesn’t have to initialized. But it must be given some value before leaving the method, which was called. 55) How does code behind defer from .aspx file Code behind contains business logic where as .aspx contains user interface. Use--------don’t have to change UI every time u change code behind it. 56) How do a web form and the code behind file know to bind the info or call that particular event? In .aspx file there is a page directive which has codebehind attribute that helps in binding info. 57) What is the deference between checked and unchecked key words in c# Both of them r used to control the overflow-checking context for integral-type arithmetic operations and conversions. Checked--------In a checked context, if an expression produces a value that is outside the range of the destination type, the result depends on whether the expression is constant or non-constant. Constant expressions cause compile time errors, while non-constant expressions are evaluated at run time and raise exceptions. Unchecked-----In an unchecked context, if an expression produces a value that is outside the range of the destination type, the result is truncated. 58) How do you make a method in child class hide parent classes same method

9

Using new keyword in the declaration of the method. 59) What is the benefit of using new key word to hide method In versioning it is helpful. 60) How do you call a base class method from child class Using base.method() 61) What does fixed key word do in c# Prevents relocation of a variable by the garbage collector. It is permitted to use this in only unsafe context. The fixed statement sets a pointer to a managed variable and "pins" that variable during the execution of statement. Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably. 62) Are there pointers in C# and how can you use them Yes…But it is unsafe to use pointers as those directly refer to address locations. You need to put unsafe key word around the code that uses pointers to make clear to runtime that it is unsafe to use. 63) How can you make a class so that it cannot be inherited? Use Sealed keyword in the declaration of that class 64) How does web.config work We define or write the modules in web.config and when the application runs it takes the modules and recognizes the configuration settings for that application. 65) How do you get better performance by using Clentside scripts As the client side script is executed before server side code you can actually check some things like validation and so on. Besides client mail, and browser detection help in things like tooltips or performing some operations as the mouse is moved and so on. 66) Can you have custom Authentication classes? Yes. You can. You have to derive from 67) What r the kinds of layout you can have in html/difference or asp. Two kinds. 1)Grid Layout-----Default. Controls are placed exactly where you draw them and they have absolute positions. U can use it where controls are not mixed text. When u actually draw controls with this layout there will be a style attribute which specifies the control position. 2)Form Layout----Controls are placed relative to other elements on the page. If you add elements at runtime you can use this. When u draw controls with this layout there won’t be a style attribute defined for this controls. 68) What is the difference between WindowsPrincipal and GenericPrincipal

10

WindowsPrincipal actually encapsulates the WindowsIdentity and it has the information about the WindowsId and it will give the role played by this Id using ‘IsInRole’ method, which returns the if that user, is in that role. U need to set the principal to windows to get WindowsPrincipal object. Where as GenericPrincipal doesn’t actually return anything. This is the default Principal that is created if you don’t set Principal. 69) Where can you store user info (username and password kind of things) Either in web.config or in database. 70) Can you have usernames in some other place other than web.config. Yes…in a DataBase. 71) How many different ways can you store the session data You can store it: in process, out of process (stateServer or SqlServer) In process is better as data is available in the same process where as out of process degrades performance but when you have Webfarm (where the web application is run on multiple machines) SqlServer is preferred or in case of security…as in process can make you loose Data when the system crashes. 72) What is Authorization? Authorization is actually giving access of the code to the users. While authentication is just checking, if the user name/login is valid. 73) Can you have your own modules in Web.config Yes you can. You use appSettings for this in the web.config or Machine.config. <section name> To get the info from these settings u use ConfigurationSettings[“key”] For example Database connection. When it has to be set only at one place or something of that sort. 74) When will the client side scripts be executed? Even before the server side code. Client side validation is provided by a jscript named WebUiValidation.js, which is downloaded separately to the client if the client browser supports DHtml. 75) What r objects that you work with when dealing with web form./ to get the api or whatever You have Page, Response, Request, Application, Session and cache objects.

11

76) What is the difference between Session object and Application object Session object is used for a single user where as Application object is used for and by the whole application. 77) What is Server.Transfer It helps in transferring some info from one web form to another. It has the form of Server.Transfer(“webform1.aspx”,true/false) First option is web form name to which you want to go and the second one is whether to take info from this form to next one or not. It works only with .aspx forms. You can’t go to .html or .htm using this. U have Response.Redirect(“webform1.aspx”/webform.html) 78) Difference between Machine.config and Web.config Both of them are used for configuring the web applications. But machine.config’s setting effect all the web applications on the machine where as web.config effects only one web application and besides it overrides any settings that were set in Machine.config. 79) Explain about the different kinds of authentication There are three kinds of authentication…Forms, Windows, and Passport Authentication. 80) Where can you do any initialization in a web application/any kind of initialization that has to be done while the application start In the Application_OnStart event you can specify any initialization. This event is present in Global.asax. This file has access to session and application objects for a web application. There can only be one Global.asax file for a web application. 81) What is the System.web refer to in web.config…module/namespace It is a module. 82) What are the different events that occur while webform is processing ASP.NET Page The page's Page_Init event is During this event, the ASP.NET page Framework raised, and the page and framework restores the control Initialization control view states are properties and postback data. restored. User Code The page's Page_Load event Read and restore values stored Initialization is raised. previously: •





Using the Page.IsPostBack property, check whether this is the first time the page is being processed. If this is the first time the page is being processed, perform initial data binding. Otherwise, restore control

12

values. Read and update control properties. The Validate method of any (There is no user hook at this stage. validator Web server controls You can test the outcome of validation is invoked to perform the in an event handler.) control's specified validation. If the page was called in Perform your application-specific response to a form event, the processing: corresponding event handler in the page is called during this • Handle the specific event stage. raised. •

Validation

Event Handling

Note Events are not raised in a particular order, except that cached control events — as specified by the control's AutoPostBack property — are always processed before the posting event. •





If the page contains Types of Validation for ASP.NET Server Controls, check the IsValid property for the page and for individual validation controls. Manually save the state of page variables that you are maintaining yourself. Check the IsValid property of the page or of individual validation controls.

Manually save the state of controls dynamically added to the page. Perform final cleanup work: •

Cleanup

The Page_Unload event is called because the page has finished rendering and is ready to be discarded.

• • •

Closing files. Closing database connections. Discarding objects. Note It is important that expensive resources, such as database connections, be 13

explicitly closed. Otherwise, they will remain open until the next garbage collection occurs. On a heavily loaded server, many open resources can adversely affect performance. 83) What r events that can occur on a page. Page_init (Occurs when the server control is initialized, which is the first step in the its lifecycle.), Page_load, (Occurs when the server control is loaded into the Page object.) AbortTransaction (Occurs when a user aborts a transaction.) CommitTransaction (Occurs when a transaction completes.) Unload (Occurs when the server control is unloaded from memory.) Disposed (Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.) Prerender (Occurs when the server control is about to render to its containing Page object.) 84) What does PreRender event do? Occurs when the server control is about to render to its containing Page object. Use this event to perform any updates before the output the server control is rendered to the page. Any changes in the view state of the server control can be saved during this event. Such changes made in the rendering phase will not be saved. 85) Why do you have to override prerender event Same as above 86) What is the best way to do paging in web applications? Using DataGrid. 87) What r the different modules that you can have in web.config Many different and we can have our own modules. Like…Authentication, authorization, customErrors, globalization, compilation, debug and many more.

14

88) What is a cookie…why do you use it? A cookie is a small piece of information stored by the browser. Each cookie is stored in a name=value; Cookie can be used as a signature for the whole client certificate.

15

Related Documents