Sie sind auf Seite 1von 70

ASP.

NET interview questions


"ASP.NET is a web application development framework for building web sites and web
applications that follows object oriented programming approach".
Following are the top 10 commonly asked Interview Questions with Answers on ASP.NET:
What is the concept of Postback in ASP.NET?
A postback is a request sent from a client to server from the same page user is already working
with.
ASP.NET was introduced with a mechanism to post an HTTP POST request back to the same
page. It's basically posting a complete page back to server (i.e. sending all of its data) on same
page. So, the whole page is refreshed.
Another concept related to this approach is "Callback" that is also asked sometimes during a
technical interview question. Click here to understand Postback Vs Callback in ASP.NET.
Difference between ASP.NET WebForms and ASP.NET MVC?
ASP.NET Web Forms uses Page controller pattern approach for rendering layout. In this
approach, every page has it's own controller i.e. code-behind file that processes the request. On
the other hand, ASP.NET MVC uses Front Controller approach. In this approach a common
controller for all pages, processes the requests.
Please follow for detailed information on WebForms Vs MVC.
Please briefly explain ASP.NET Page life Cycle?
ASP.NET page passes through a series of steps during its life cycle. Following is the high-level
explanation of life cycle stages/steps.
Initialization: Controls raise their Init event in this stage.Objects and variables are initializes for
complete lifecyle of request.
LoadViewState: is a post back stage and loads the view state for the controls that enabled its
view state property.
LoadPostBackData: is also a post back stage and loads the data posted for the controls and
update them.
Load: In this stage page as well as all the controls raise their Load event. Till this stage all the
controls are initialized and loaded. In most of the cases, we are coding this event handler.
RaisePostBackEvent: is again a postback stage. For example, it's raise against a button click
event. We can easily put our code here to perform certain actions.
SaveViewState: Finally, controls state is saved in this stage before Rendering HTML.
Render: This is the stage where HTML is generated for the page.
Dispose: Lastly, all objects associated with the request are cleaned up.
For very detailed explanation of Page Life Cycle is explained here.
What is the difference between custom controls and user controls?
Custom controls are basically compiled code i.e. DLLs. These can be easily added to toolbox, so
it can be easily used across multiple projects using drag and drop approach. These controls are
comparatively hard to create.
But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but
tightly couple with respect to User Interface and code. In order to use across multiple projects,
we need to copy and paste to the other project as well.
What is the concept of view state in ASP.NET?
As in earlier question, we understood the concept of postback. So, in order to maintain the state
between postbacks, ASP.NET provides a mechanism called view state. Hidden form fields are
used to store the state of objects on client side and returned back to server in subsequent request
(as postback occurs).
Difference between Response.Redirect and Server.Transfer?
In case of Response.Redirect, a new request is generated from client-side for redirected page. It's
a kind of additional round trip. As new request is generated from client, so the new URL is
visible to user in browser after redirection.
While in case of Server.Transfer, a request is transferred from one page to another without
making a round trip from client. For the end user, URL remains the same in browser even after
transferring to another page.
Please briefly explain the usage of Global.asax?
Global.asax is basically ASP.NET Application file. Its a place to write code for Application-
level events such as Application start, Application end, Session start and end, Application error
etc. raised by ASP.NET or by HTTP Modules.
There is a good list of events that are fired but following are few of the important events in
Global.asax:
Application_Init occurs in case of application initialization for the very first time.
Application_Start fires on application start.
Session_Start fires when a new user session starts
Application_Error occurs in case of an unhandled exception generated from
application.
Session_End fires when user session ends.
Application_End fires when application ends or time out.
What are the different types of Validation controls in ASP.NET?
In order to validate user input, ASP.NET provides validation server controls. All validation
controls inherits from BaseValidator class which contains the common validation properties and
methods like ControlToValidate, Enabled, IsValid, EnableClientScript,
ValidationGroup,Validate() etc.
ASP.NET provides a range of validation controls:
RequiredFieldValidator validates compulsory/required input.
RangeValidator validates the range. Validates that input falls between the given range
values.
CompareValidator validates or compares the input of a control with another control
value or with a fixed value.
RegularExpressionValidator validates input value against a defined regular
expression pattern.
CustomValidator allows to customize the validation logic with respect to our
application logic.
ValidationSummary displays all errors on page collectively.
What are the types of Authentication in ASP.NET?
There are three types of authentication available in ASP.NET:
Windows Authentication: This authentication method uses built-in windows security
features to authenticate user.
Forms Authentication: authenticate against a customized list of users or users in a
database.
Passport Authentication: validates against Microsoft Passport service which is basically a
centralized authentication service.
What are Session state modes in ASP.NET?
ASP.NET supports different session state storage options:
In-Process is the default approach. It stores session state locally on same web server
memory where the application is running.
StateServer mode stores session state in a process other than the one where application is
running. Naturally, it has added advantages that session state is accessible from multiple
web servers in a Web Farm and also session state will remain preserved even web
application is restarted.
SQLServer mode stores session state in SQL Server database. It has the same advantages
as that of StateServer.
Custom modes allows to define our custom storage provider.
Off mode disables session storage

ASP.NET Application and Page Life Cycle

Introduction
In this article, we will try to understand what the different events are which take place right from
the time the user sends a request, until the time the request is rendered on the browser. So we
will first try to understand the two broader steps of an ASP.NET request and then we will move
into different events emitted from HttpHandler, HttpModule and ASP.NET page object. As
we move in this event journey, we will try to understand what kind of logic should go in each
and every one of these events.
you can catch me on my daily free training here.
The Two Step Process
From 30,000 feet level, ASP.NET request processing is a 2 step process as shown below. User
sends a request to the IIS:
ASP.NET creates an environment which can process the request. In other words, it creates the
application object, request, response and context objects to process the request.
Once the environment is created, the request is processed through a series of events which is
processed by using modules, handlers and page objects. To keep it short, let's name this step as
MHPM (Module, handler, page and Module event), we will come to details later.

In the coming sections, we will understand both these main steps in more detail.
Creation of ASP.NET Environment
Step 1: The user sends a request to IIS. IIS first checks which ISAPI extension can serve this
request. Depending on file extension the request is processed. For instance, if the page is an
.ASPX page, then it will be passed to aspnet_isapi.dll for processing.

Step 2: If this is the first request to the website, then a class called as ApplicationManager
creates an application domain where the website can run. As we all know, the application
domain creates isolation between two web applications hosted on the same IIS. So in case there
is an issue in one app domain, it does not affect the other app domain.

Step 3: The newly created application domain creates hosting environment, i.e. the
HttpRuntime object. Once the hosting environment is created, the necessary core ASP.NET
objects like HttpContext , HttpRequest and HttpResponse objects are created.

Step 4: Once all the core ASP.NET objects are created, HttpApplication object is created to
serve the request. In case you have a global.asax file in your system, then the object of the
global.asax file will be created. Please note global.asax file inherits from HttpApplication
class.
Note: The first time an ASP.NET page is attached to an application, a new instance of
HttpApplication is created. Said and done to maximize performance, HttpApplication
instances might be reused for multiple requests.

Step 5: The HttpApplication object is then assigned to the core ASP.NET objects to process
the page.

Step 6: HttpApplication then starts processing the request by HTTP module events, handlers
and page events. It fires the MHPM event for request processing.
Note: For more details, read this.

The below image explains how the internal object model looks like for an ASP.NET request. At
the top level is the ASP.NET runtime which creates an Appdomain which in turn has
HttpRuntime with request, response and context objects.

Process Request using MHPM Events Fired
Once HttpApplication is created, it starts processing requests. It goes through 3 different
sections HttpModule , Page and HttpHandler. As it moves through these sections, it
invokes different events which the developer can extend and add customize logic to the same.
Before we move ahead, let's understand what are HttpModule and HttpHandlers. They help
us to inject custom logic before and after the ASP.NET page is processed. The main differences
between both of them are:
If you want to inject logic based in file extensions like .ASPX, .HTML, then you use
HttpHandler. In other words, HttpHandler is an extension based processor.

If you want to inject logic in the events of ASP.NET pipleline, then you use HttpModule.
ASP.NET. In other words, HttpModule is an event based processor.

You can read more about the differences from here.
Below is the logical flow of how the request is processed. There are 4 important steps MHPM as
explained below:

Step 1(M: HttpModule): Client request processing starts. Before the ASP.NET engine goes and
creates the ASP.NET HttpModule emits events which can be used to inject customized logic.
There are 6 important events which you can utilize before your page object is created
BeginRequest, AuthenticateRequest, AuthorizeRequest, ResolveRequestCache,
AcquireRequestState and PreRequestHandlerExecute.

Step 2 (H: HttpHandler): Once the above 6 events are fired, ASP.NET engine will invoke
ProcessRequest event if you have implemented HttpHandler in your project.

Step 3 (P: ASP.NET page): Once the HttpHandler logic executes, the ASP.NET page object is
created. While the ASP.NET page object is created, many events are fired which can help us to
write our custom logic inside those page events. There are 6 important events which provides us
placeholder to write logic inside ASP.NET pages Init, Load, validate, event, render and
unload. You can remember the word SILVER to remember the events S Start (does not signify
anything as such just forms the word) , I (Init) , L (Load) , V (Validate), E (Event) and R
(Render).

Step4 (M: HttpModule): Once the page object is executed and unloaded from memory,
HttpModule provides post page execution events which can be used to inject custom post-
processing logic. There are 4 important post-processing events PostRequestHandlerExecute,
ReleaserequestState, UpdateRequestCache and EndRequest.
The below figure shows the same in a pictorial format.

In What Event Should We Do What?
The million dollar question is in which events should we do what? Below is the table which
shows in which event what kind of logic or code can go.
Section Event Description
HttpModule BeginRequest
This event signals a new request; it is guaranteed to be
raised on each request.
HttpModule AuthenticateRequest
This event signals that ASP.NET runtime is ready to
authenticate the user. Any authentication code can be
injected here.
HttpModule AuthorizeRequest
This event signals that ASP.NET runtime is ready to
authorize the user. Any authorization code can be
injected here.
HttpModule ResolveRequestCache
In ASP.NET, we normally use outputcache directive to
do caching. In this event, ASP.NET runtime determines if
the page can be served from the cache rather than
loading the patch from scratch. Any caching specific
activity can be injected here.
Section Event Description
HttpModule AcquireRequestState
This event signals that ASP.NET runtime is ready to
acquire session variables. Any processing you would like
to do on session variables.
HttpModule PreRequestHandlerExecute
This event is raised just prior to handling control to the
HttpHandler. Before you want the control to be
handed over to the handler any pre-processing you
would like to do.
HttpHandler ProcessRequest
Httphandler logic is executed. In this section, we will
write logic which needs to be executed as per page
extensions.
Page Init
This event happens in the ASP.NET page and can be
used for:
Creating controls dynamically, in case you have
controls to be created on runtime.
Any setting initialization.
Master pages and the settings.
In this section, we do not have access to viewstate,
postedvalues and neither the controls are initialized.
Page Load
In this section, the ASP.NET controls are fully loaded and
you write UI manipulation logic or any other logic over
here.
Page Validate
If you have valuators on your page, you would like to
check the same here.

Render
Its now time to send the output to the browser. If you
would like to make some changes to the final HTML
which is going out to the browser, you can enter your
HTML logic here.
Page Unload
Page object is unloaded from the memory.
HttpModule PostRequestHandlerExecute
Any logic you would like to inject after the handlers are
executed.
HttpModule ReleaserequestState
If you would like to save update some state variables
like session variables.
HttpModule UpdateRequestCache
Before you end, if you want to update your cache.
HttpModule EndRequest
This is the last stage before your output is sent to the
client browser.
A Sample Code for Demonstration
With this article, we have attached a sample code which shows how the events actually fire. In
this code, we have created a HttpModule and Httphandler in this project and we have
displayed a simple response write in all events, below is how the output looks like.
Below is the class for HttpModule which tracks all events and adds it to a global collection.
Collapse | Copy Code
public class clsHttpModule : IHttpModule
{
......
void OnUpdateRequestCache(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnUpdateRequestCache");
}
void OnReleaseRequestState(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnReleaseRequestState");
}
void OnPostRequestHandlerExecute(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnPostRequestHandlerExecute");
}
void OnPreRequestHandlerExecute(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnPreRequestHandlerExecute");
}
void OnAcquireRequestState(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnAcquireRequestState");
}
void OnResolveRequestCache(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnResolveRequestCache");
}
void OnAuthorization(object sender, EventArgs a)
{
objArrayList.Add("httpModule:OnAuthorization");
}
void OnAuthentication(object sender, EventArgs a)
{

objArrayList.Add("httpModule:AuthenticateRequest");
}
void OnBeginrequest(object sender, EventArgs a)
{

objArrayList.Add("httpModule:BeginRequest");
}
void OnEndRequest(object sender, EventArgs a)
{
objArrayList.Add("httpModule:EndRequest");
objArrayList.Add("<hr>");
foreach (string str in objArrayList)
{
httpApp.Context.Response.Write(str + "<br>") ;
}
}
}
Below is the code snippet for HttpHandler which tracks ProcessRequest event.
Collapse | Copy Code
public class clsHttpHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
clsHttpModule.objArrayList.Add("HttpHandler:ProcessRequest");
context.Response.Redirect("Default.aspx");
}
}
We are also tracking all the events from the ASP.NET page.
Collapse | Copy Code
public partial class _Default : System.Web.UI.Page
{
protected void Page_init(object sender, EventArgs e)
{

clsHttpModule.objArrayList.Add("Page:Init");
}
protected void Page_Load(object sender, EventArgs e)
{
clsHttpModule.objArrayList.Add("Page:Load");
}
public override void Validate()
{
clsHttpModule.objArrayList.Add("Page:Validate");
}
protected void Button1_Click(object sender, EventArgs e)
{
clsHttpModule.objArrayList.Add("Page:Event");
}
protected override void Render(HtmlTextWriter output)
{
clsHttpModule.objArrayList.Add("Page:Render");
base.Render(output);
}
protected void Page_Unload(object sender, EventArgs e)
{
clsHttpModule.objArrayList.Add("Page:UnLoad");
}}
Below is how the display looks like with all events as per the sequence discussed in the previous
section.

Zooming ASP.NET Page Events
In the above section, we have seen the overall flow of events for an ASP.NET page request. One
of the most important sections is the ASP.NET page, we have not discussed the same in detail.
So lets take some luxury to describe the ASP.NET page events in more detail in this section.
Any ASP.NET page has 2 parts, one is the page which is displayed on the browser which has
HTML tags, hidden values in form of viewstate and data on the HTML inputs. When the page is
posted, these HTML tags are created in to ASP.NET controls with viewstate and form data tied
up together on the server. Once you get these full server controls on the behind code, you can
execute and write your own login on the same and render the page back to the browser.

Now between these HTML controls coming live on the server as ASP.NET controls, the
ASP.NET page emits out lot of events which can be consumed to inject logic. Depending on
what task / logic you want to perform, we need to put this logic appropriately in those events.
Note: Most of the developers directly use the page_load method for everything, which is not a
good thought. So its either populating the controls, setting view state, applying themes, etc.,
everything happens on the page load. So if we can put logic in proper events as per the nature of
the logic, that would really make your code clean.
Seq Events
Controls
Initialized
View
state
Available
Form data
Available
What Logic can be written here?
1 Init No No No
Note: You can access form data etc. by using
ASP.NET request objects but not by Server
controls.Creating controls dynamically, in case
you have controls to be created on runtime. Any
setting initialization.Master pages and
them settings. In this section, we do not have
access to viewstate , posted values and neither
the controls are initialized.
2
Load view
state
Not
guaranteed
Yes
Not
guaranteed
You can access view state and any synch logic where
you want viewstate to be pushed to behind code
variables can be done here.
3 PostBackdata
Not
guaranteed
Yes Yes
You can access form data. Any logic where you want
the form data to be pushed to behind code variables
can be done here.
4 Load Yes Yes Yes
This is the place where you will put any logic you
want to operate on the controls. Like flourishing a
Seq Events
Controls
Initialized
View
state
Available
Form data
Available
What Logic can be written here?
combobox from the database, sorting data on a grid,
etc. In this event, we get access to all controls,
viewstate and their posted values.
5 Validate Yes Yes Yes
If your page has validators or you want to execute
validation for your page, this is the right place to the
same.
6 Event Yes Yes Yes
If this is a post back by a button click or a dropdown
change, then the relative events will be fired. Any
kind of logic which is related to that event can be
executed here.
7 Pre-render Yes Yes Yes
If you want to make final changes to the UI objects
like changing tree structure or property values,
before these controls are saved in to view state.
8
Save view
state
Yes Yes Yes
Once all changes to server controls are done, this
event can be an opportunity to save control data in
to view state.
9 Render Yes Yes Yes
If you want to add some custom HTML to the output
this is the place you can.
10 Unload Yes Yes Yes Any kind of clean up you would like to do here.



Interview Question for 3-6 Year experience in .Net Technologies- Part I

Below I am posting the questions and answers for the short questions for 3-6 years
guys. These questions will be helpful for those who are preparing for the interview
or attending the interviews. This will be helpful for the last minute preparation in
quickest way.
If anyone has better answer, please reply to this post as that will be useful for all of
us.

CLR and C#

1. Types of Authentication and Authorization in IIS.
A. Types of Authentication: Anonymous Authentication, Windows Authentication,
Digest Authentication
Types of Authorization:- Anonymous

2. Types of Authentication and Authorization in ASP.Net.
A. Types of Authentication: Windows Authentication, Forms Authentication
Types of Authorization:- File Authorization and URL Authorization

3. ASP.Net Life cycle.
A. The request starts with the client and processed through IIS. In IIS, there are 2
utilities- INetInfo.exe and ASPNet_ISAPI.dll the InetInfo.exe checks for the syntax
and semantics of the request and then the request goes to the ASPNet_ISAPI.dll
which is the filter to filter the .aspx files. Here the URL request split in to 2 parts-
virtual directory and webpage. Now worker process which is nothing but the
application factory basically contains all the virtual directories and checks for the
current virtual directory. If this is first request, then there will be no Virtual
directory available. Now the worker process (W3wp.exe) creates a memory area
called as AppDomain to check for the current page. As AppDomain is the Page
Handler factory so it contains all the processes pages. If this is the new page then it
will not find here. The request further move to the HttpPipeline where the actual
execution of the page happened by using the ProcessRequest method and creates
the events of the page. After creation of event and execution of all the event, the
HTML page gets back to the user.

4. ASP.Net Page Life Cycle.
A. There are few events which gets generated during the page execution like:
Page_BeginRequest, Page_Init, Page_Load, Page_Prerender, Page_Render,
Page_Unload etc
For the details of the page life cycle, you can follow the previous question.

5. What are types: Value Type and Reference Type?
A. Value type holds data directly, Value type stored in the stack memory, we can
get the direct value of the value types. Value type data type cant be null.
Reference types: This type doesnt hold the data directly. They hold the address on
which the actual data present. They stored in heap memory, Can have default
values.
We can make and work with null reference type.

6. Boxing and Unboxing: Terminology, Advantages and Disadvantages.
A. Converting the value type data type in to the Reference type is called as Boxing.
Converting the Reference type data type and keep its value to stack is called as the
reference type.
byte b= 45;
Object o = b.Tostring();
The Advantage of boxing and unboxing is that we can convert the type of the object
in to another type. The disadvantage is that it requires lot of memory and CPU
cycles to convert from one type to another type.
Object o=10;
Int i= Convert.ToInt32(o.ToString());

7. What is Type Safety?
A. TypeSafe is a way through which the application or framework that the memory
will not be leaked to outside environment. E.g. C# is the type safe language where
you must have to assign any object before using it. In VB.Net it will take the default
value. So C# is the type safe language while VB.Net is not.

8. What is Strong Name?
A. Strong Name (SN) is used to make the dll as the unique as:
SN -k fileName.dll
Now it will have the unique name. This assembly when placed in the GAC, it will
treat as the unique with its version number and other details. 2 assemblies with the
same name can exist in the GAC but both will have different version. The CLR takes
the latest version assembly while running the application.

9. What are Extensions, modules and handlers?
A. HttpModule and HttpHandler are the utilities which are used in the HttpPipeline
under the ASP.Net page life cycle. When the request received to HttpPipeline, the
HttpModule checks for the Authentication of the request and then it route the
request to the respective handler. After that HttpHandler takes that request and
process it. After Processing the request again the HttpModule takes the response
and send it back to the worker process and finally to the user.

10. What is worker process?
A. Worker process (w3wp.exe) is an executable which is also called as the
Application Factory. This is used for the execution of the request and handling of
the request for the current web page.

11. CLR and DLR?
A. CLR (Common Language Runtime) is the utility in the .Net framework to run the
application. It is the run-time engine which actually executes the application with
many responsibilities like taking care of memory management, versioning, CasPol
etc.
DLR is new with .Net 4.0 which is the Dynamic Language Runtime and used to run
the application on the fly wherever required. CLR runs as statically while DLR runs
dynamically.

12. In case more than one version of an installable is installed, which version is
invoked by default?
A. By default the CLR will take and invoke the latest version of the dll and execute
it accordingly. There could be the same name assemblies exists in the GAC but they
will have different versions altogether for their uniqueness.
So while running the application, CLR takes the latest version assembly and use in
the application.

13. What are Globalization and localization? How to implement them?
A. Globalization is the concept of developing the application in more than one
language while the Localization is used for a particular language. Like if we develop
the application in more than one language we need to create the resource files
(.resx) by using System. Globalization and when we open the application in a
particular language, then the localizations used to convert that application to the
selected language.

14. What is assembly, GAC? Where they are physically located?
A. Assembly is the collection of classes, namespaces, methods, properties which
may be developed in different language but packed as a dll. So we can say that dll
is the assembly.
There are 3 types of assemblies- Private Assembly, Shared Assembly, and Satellite
Assembly.
GAC (Global Assembly Cache)- When the assembly is required for more than one
project or application, we need to make the assembly with strong name and keep it
in GAC or in Assembly folder by installing the assembly with the GACUtil command.
To make the assembly with strong name:
SN -k MyDll.dll
And to install it in GAC:
GacUtil -i MyDll.dll
GAC assemblies are physically stored in Assembly folder in the system.

15. How to configure HTTPS for a web application?
A. To configure the HTTPS (HTTP with Secure) for the web application, we need to
have a client certificate. We can purchase the client certificate from the trusted
providers and then we need to install that provider for our site. By implementing
the HTTPS, all the data which is passing will be in encrypted format and will be
more secure.

16. What are in-proc and out-proc? Where are data stored in these cases?
A. In-Proc and Out-Proc is the types of Sessions where the session data can be
stored in the process memory of the server and in the separate state server.
When the session data is stored in the process memory of the server, the session is
called as the In-Proc server. In this case when the server is restarted, the session
data will be lost.
When the session data is stored in the separate server like in state server or in Sql
Server, the type of session is called as the Out-Proc session. In this case, if the
server where the application is running is restarted, the session will be still remain
in the separate servers.
So in the in-Proc session state, the session data is stored in the Process memory of
the Server where the application is running.
In the Out-proc session state, the session data is stored in the separate server-
may be state server or in sql server.

17. When the View state is saved, and when is it loaded? How to enable/ disable
View states?
A. View State data is stored in the current page in base64 encoded format. It gets
loaded with the page and displays the values to the controls after the decoded.
Internally it actually saves the check-sum of all the control data where the view
state is enabled.so that when the page gets loaded due to any post back, it again
finds the check-sum and then decodes the Base64 encoded string and gets back
the same data to the controls. We can see the view state base 64 encoded string in
View Source of the page. It will be like
_VIEWETATE="DSDSDF8DGDGDFGFD5FDGGDJFF23BNN457M9UJOG" this.
View state won't take the client or server memory to keep the view state data.

18. Difference between GET and POST. Which one is more secure?
A. GET and POST methods are used for the data transfer between the web pages.
GET mainly used for small data which is not secure because in case of GET method,
the data which we are passing will be visible in the url so we can't keep the secure
data which will be visible in the url. There is also limited data which can be passed
in case of GET method (max 255 character).
POST is used for transferring the huge data between the pages where we can keep
the secure data and can transfer it. In case of using the POST method, the data
which is transferring between the pages will not be visible so it is more secure than
the GET method. Also there is no limit for POST method to post the data to the next
page.
POST is more secure.

19. What are Razor engines? How is it diff from ASP Engines?
A. RAZOR engine is the new concept in the MVC 3 which is mainly used to create
the views in the MVC applications. It created the cshtml pages for the MVC
application and cshtml pages can be generated automatically by using the Razor
engine.ASP engine create the aspx pages while Razor engine creates the pages.

20. Pros and cons of JavaScript and AJAX.
A. JavaScript is a scripting language and mainly used for client side validation. We
can validate the client side data before sending to the server. So by this we can
improve the performance of the application.
Ajax is Synchronous JavaScript and XML which is used for the Asynchronous calls
from the server. It uses internally the JavaScript for making the call and use XML
for the Data Transfer. It basically uses the XmlHttpRequest for the asynchronous
calls to the server and communicates with the XML data which is platform
independent. So Ajax can be used with any technology.

21. In how many different ways can JavaScript be used/called in an application?
A. JavaScript can be used for Client Side validation, can also be used for calling of
server side methods and functions, can be used for calling the web services etc.

22. What needs to be done to call a JavaScript function from code behind?
A. If we want to call the JavaScript function from the code behind, we need to
attach the JavaScript to the events in the page_load event as:
protected void btnSave_cliekc9object sender, EventArgs e)
{
btnSave.Attributes.Add("onclick,"JavaScript: retrun Validatedata();");
}
Here ValidateData is the JavaScript function which can be used to validate the page
data and if validation fails, it will return and will not execute the server side
btnSave_click event.

23. Difference between Server Controls and User controls?
A. User controls are used for the re-usability for the controls in the application. By
using the user control, we can use the same control in the various pages. User
controls can be created by combining more than one control. To use the user
controls, first we need to register them in the web page where we want to use that
control. A separate copy is need in each page where we want to use the user
control. User controls can't be included in to the toolbox.
Server controls are those controls which can be found in the toolbox and can be
directly drag to the application like textbox, button etc. For the server control, only
1 copy of the control is needed irrespective of the number of web pages. If we want
10 text-boxes to be added in our web page, we need only 1 copy of the textbox in
the toolbox and can be dragged 10 times.

24. Difference between Var, object and Dynamic types.
A. var is the keyword introduced with .net 3.5 and used to store any kind of data
like data-set, data table, int, float, char etc. We can keep any kind of data in the
var variable.
var myVar = new String[] {"hello", "world!!"} ;
Here the myVar is the var type variable which is used to store the string array. Like
this we can store any type of data into the var.
Object is the type which is used to store the objects of any kind. These objects
need to be type caste when required.
Like object mybject = "Hello"
Here the myObject variable of object type is used to keep the string variable. Now
when we want this variable value, we need to typecast it like
string strvar= (string) myobject;
Dynamic- Its a keyword introduces with the .net 4.0 and used to keep the data
similar to the var keyword. The difference between the var and dynamic is that the
dynamic variable uses the same memory location to store the object and not
changes throughout the application.

25. Difference between Functions and methods.
A. in.Net terminology, both are same. in general, we use method in .net but in
scripting language we use function like JavaScript function.
Here the difference can be Function always returns a value which method may or
may not. It depends upon the return type of the method.

26. Difference between Abstract classes and Interface. Explain with scenario where
to implement one?
A. Collection of the Abstract (Incomplete) and Concrete (complete) methods is
called as the Abstract class. If there is at least one abstract method in a class, the
class must be abstract class.
When there is the similar behavior, we can use the abstract class.
e.g. We want to calculate the area of few component. As this is not generic to the
application. We have only few component- like Circle, Ellipse, parabola, Hyperbola,
Triangle etc.
So we can create an abstract class and implement it like below:
public abstract class MyAbstractClass
{
// some other concrete members
public abstract void Area();// abstract member
}
Now in the child class, lets say i have a circle class and want to calculate the area
of the circle:
public class Cicle: MyAbstractClass
{
public override void Area()
{
// calculate the area of the circle
}
}
In the similar fashion, we can calcite the area of other shapes.
Collection of abstract members is called as the Interface. When the behavior is not
similar, we need to use the interface. All the members of the interface
must be overrides in the child class.
e.g. Print functionality of the application can have an interface like:
interface Inf
{
void Print();
}
Now as this is the generic functionality and can be implemented in any of the page
so we have taken it as interface. Now we can implement this functionality in to any
page like:
class MyClass:Inf
{
public void print
{
// write details about the print
}
// Here we can implement any kind of print-like print to excel, xml, word all depends on the
our decision.
}

27. Different forms of Polymorphism. Differences between Abstraction and
Polymorphism.
A. Polymorphism is to use the same function in many forms. The polymorphism is
of 2 types-
a. Classical polymorphism (Overloading)
b. AdHoc polymorphism (Overriding)
When the runtime (CLR) find the behavior of class members at the runtime of the
program, it is called as the AdHoc polymorphism or Overriding.in this the method
name is same but they are implemented in the different class. We use virtual
keyword in the base class method to be overrides in the child class using the
override keyword.
e.g.
public class MyClass
{
Public int Add(int a, int b)
{
Return a+b;
}
Public int Add(int a, int b, int c)
{
Return a+b+c;
}
}
When the run-time (CLR) find the behavior of class members at the compilation of
the program, it is called as the Classical polymorphism or Overloading.in this the
method name is same but there prototypes (parameters) are different and it is
implemented in the same class.
e.g.
Public class MyBaseClass
{
Public virtual void Show(string message)
{
Console.WriteLine(Your message is : + message);
}
}
Public class MyChildClass: MyBaseClass
{
public override void Show(string message)
{
Console.WriteLine(Your new message is : + message);
}
}
Abstraction is the behavior to get the required functionality in the child class. So we
dont matter whatever is written in the base class. We only need to force the child
class to implement my required functionality.
Abstract keyword is used to get the abstraction behavior.

28. What are Delegates and Events?
A. A Delegate is an object, which points to another method in the application.
Delegate holds, name of the method, arguments of the method (if any) and the
return type of the method.
See the below points regarding the Delegate:-
delegate keyword is sealed type in System. Multicast namespace.
Delegate works like a function pointer in C language.
Delegate holds the address of the function.
Delegate hides the actual information which is written inside the method
definition.
A delegate can hold address of a single function as well as the address of
multiple functions.
There are 2 types of delegate- Single-cast delegate (hold single function)
and Multicast delegate(hold multiple functions).
Addition and subtraction are allowed for the delegates but NOT
multiplication and division. It means, we can add delegates, subtract delegates etc.
e.g. To create a single cast delegate, first we can create a class with a method as:
public class DelegateDemo
{
public void Show(string msg)
{
Console.WriteLine(msg);
}
}
Now we can call the method Show using the delegate as:
public delegate void MyDelegate(string message); //declare delegate
now we need to create the object of the delegate with the address of the method
as:
DelegateDemo obj = new DelegateDemo();//class object
MyDelegate md= new MyDelegate(obj.Show(Hello World!!));
md(); // call the delegate
We can create the events and event handler by using delegate with the below
syntax:
public delegate void textChangedEventHandler(Object sender, TextEventArgs e);
This event handler will be used to handle the textbox text changed event.
We can get more details about the delegate and events from the below link:
http://msdn.microsoft.com/en-in/library/orm-9780596521066-01-17.aspx

29. Covariance and Contra-variance.
A. covariance and contravariance are the new features added with the .net 4.0.
They are basically used for the implicit reference conversion for different .net types
like array, delegate, and generic etc
You can go to the below link for more details with the examples that how we can
use the covariance and contrvariance to implicate reference conversion:
http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-
faq.aspx

30. What are Extension methods?
A. Extension methods are special types of methods which are static methods but
called as the instance methods. The extension methods are added with the .Net
framework 3.5 and with the Visual Studio 2008.
These methods wont affect the existing class and the label. These methods are
used for the extra behavior which the calls can provide. There is no need to build
the class again if we add any extension method to the class.
There are various inbuilt methods added in .Net 3.5 with the introduction of LINQ.
We can see the extension methods like Order By when we use the Linq as:
e.g.
int[] numbers = { 10, 45, 15, 39, 21, 26 };
var orderedNumbers = numbers.OrderBy(a => a);


31. What are Anonymous methods and Lambda Expression?
A. Anonymous methods are those methods which does not have the name. As they
dont have the name, so there is no way to call these methods. These methods are
created by using the work delegate as below:
button1.Click += delegate{listBox1.Items.Add(textBox1.Text)};
Lambda Expression: Its an easy way to create anonymous functions. It is also an
anonymous function which has the capability to contain expressions and
statements. We can create the delegate and expression tree types using the
lambda expression.
For more details regarding the anonymous method and lambda express, you can go
through the below link:
http://www.codeproject.com/Articles/47887/C-Delegates-Anonymous-Methods-and-
Lambda-Expression

32. Multithreading. How to implement Multithreading?
A. Executing more than one process simultaneously called as multithreading. To
implement the multithreading concept, we need to use the System. Threading .dll
assembly and the System. Threading namespace.
To write the thread program, we need to create a class with the method. Now we
can create the thread object and then pass the method by using the class object to
the method.
After that we need to create the ThreadStart delegate which will call the actual
method of the class.
You can go through below link for more explanation and other details regarding the
implementation and the code snippet:
http://www.codeproject.com/Articles/1083/Multithreaded-Programming-Using-C

33. Which interface is used to-
a. Convert Boolean values to Visibility values?
b. Compare two integer values?
c. Compare String values?
A. Check the below interfaces which are used in these scenarios:
a. Convert Boolean values to Visibility values?
b. Compare two integer values?- IComparable interface
c. Compare String values? IComparer interface


SQL Server

34. What is the difference between a View and a Cursor?
A. View: It is one of the database object which is also called as virtual table. We
can also say that it is a window through which we can see some part of database.
View is also called as stored query because we are going to fetch some data using
View.
View doesnt contain any data. Its just a virtual table which is used to get the
records from the base table for which the view is created. View is faster than ad hoc
queries because when we create the view and execute it once. Next time onwards it
will be available as the compiled format. So whenever the view is called, it will just
execute rather than compiling.
Cursor: Cursor is a database object which is also the buffer area which is created as
a result of any sql statement to hold the intermediate values.
Views are used to format the rows individually. By using the views, we can process
the individual rows. There are 4 types of cursors in Sql Server-
a. Static Cursor
b. Dynamic Cursor
c. Key set cursor
d. Read-only cursor

35. How to execute multiple update on different conditions in a single query?
A. To execute multiple update using a single Sql update statement is the new
feature available with the SQL Server 2008. In this, we can update multiple rows
using a single update command.

36. Left outer joins and Right Outer joins
A. Joins are used to join 2 or more tables using some conditions. There are 3 types
of Joins in SQL Server database-
a. Left Outer Join
b. Right Outer Join
c. Full Join
In order to extract the matched row from both the tables and unmatched row from
the first table, left Outer join is used. The syntax for left outer join condition is:
T.Col1* = T2.Col1
In order to extract the matched row from both the tables and unmatched row from
the second table, right Outer join is used. The syntax for right outer join condition
is:
T.Col1 = *T2.Col1
In order to extract the matched row from both the tables and unmatched row from
the first table and then unmatched row from the second table, full join is used. The
syntax for full join condition is:
T.Col1* = *T2.Col1

37. Exception handling.
A. Exception Handling is the way to handle the unexpected error. From the SQL
Server 2005 version, trycatch block is also supported to catch the exceptions in
SQL Server database. There is various other ways to catch the error like @@Error
which is the global variable and used to get the error. RaiseError is another inbuilt
method which is used to display the error.

38. What is Performance Tuning? How do you implement it.
A. Performance Tuning is the process through which we can optimize the SQL
Server objects like functions, triggers, stored procedure so that we can achieve
high response time to the front end. In the performance tuning process we
generally check for the below point and optimize the objects processing:
a. Through Query Execution plan, check for the processing time of the query
execution.
b. Check the join conditions and break all the condition for executions of the
queries individually
c. Check for the error prone process, conditions in the queries.
d. Check for the loops whether they are terminated if any error occurs
e. Check for the processes which are taking more time in execution and how to
reduce the response time.

39. Difference between Having and Where clauses.
A. When the where clause is not able to evaluate the condition which consists of
group functions, Having clause is used. Having clause is always followed by the
Group By clause.
Where clause is used to filter the records based on the conditions. If there is the
requirement to get the group data in the select statement and where clause is not
able to get it, we can use the Having clause.
e.g. Display DeptNo, No.of Employees in the department for all the departments
where more than 3 employees are working
SELECT DEPTNO, COUNT(*) AS TOTAL_EMPLOYEE
FROM EMP
GROUP BY DEPTNO HAVING COUNT(*) >3

40. Difference between Temp tables and Tables variables?
A. Temp Table in SQL Server:
a. Temp table is the special type of tables which are used to store the intermediate
data of the actual table.
b. Temp tables are only visible to the current sessions of the sql server instance.
When the session end, these table data automatically drops.
c. We cant join the temp tables as they dont allow the foreign key constraints.
d. Temp tables are created in TempDB database.
e. We can use the same temp table name for the different user sessions.
f. Mostly used in stored procedure to handle the intermediate data.

41. What does @ and @@ suffixed by property names specify?
A. @- This is used for the variable declaration
e.g. @name varchar2(50)
@@- This is used for the Global variable declaration
e.g. @@Error=0

42. Self-join queries.
A. Self-Join is a type of join which is used to join the same table by creating the
second instance of the same table. So we join 2 instances of the same table in case
of self-join. This type of join is used when there is the requirement to get the
referenced data which is available in the same table.
e.g. A table contains EmpId, Ename and ManagerId
As the manager id is also an employee id. Now if we want that who is the manager
of which employee. In this situation, we need to create the instance of the same
table and get the required data as:
SELECT EMPID, ENAME, ENAME AS [MANAGER NAME]
FROM EMP E1, EMP E2
WHERE E1.EMPID= E2.MANAGERID

43. Types of Index.
A. Indexes are one the database objects which is used to improve the performance
of the database queries. it reduces the table scan while retrieving the data from the
database and the search gets fast-
There are 2 types of indexes used in the SQL server:
a. Clustered index
b. Non clustered index
There are 3 more types of index but those comes under the above two-
a. unique index
b. Composite Index
c. XML Index-added in SQL Server 2005
The index basically works on searching like binary tree where the root value is the
finding value and it will be compared with the partitioned value of the tree.

44. Difference between Primary key, Unique key and Candidate key?
A. Primary Key- It is a key to make the unique identification of the row in a table. It
doesnt allow null values in the primary key column. We can create the lookup
columns based on the primary key. One table allows maximum of 1 primary key
and in 1 table, we can create the primary key column by using 16 columns. Due to
one of the normalization rule, we have to create primary key for the table to make
the rows unique.
Unique Key:- Primary Key+ Not null is called as unique key. Unique key is also used
to make the rows as unique in a table. The only difference between primary key
and unique key is that primary key doesnt allow null value while the unique key
allow. The limitation of the null in unique key is that it allows only one Null so in
only one row; we can make the key as null for the unique key.
Candidate key- the key other than primary key to make the rows as unique is called
as candidate key. In candidate key, we take the columns which are not in the
primary key and make the key for uniqueness of the row.

45. What is the default value for Date type. What are Min and Max values for Date
in 2008.
A. The default value of Date is CURRENT_TIMESTAMP
Below are the new date and time values in Sql Server 2008:
In SQL Server 2008:
1. DateTime2
Min Value: 0001-01-01 00:00:00.0000000
Max Value: 9999-12-31 23:59:59.9999999
2. Date
Min Value: 0001-01-01
Max Value: 9999-12-31

You can go through the below link for couple of work around:
http://dhaneenja.blogspot.in/2008/06/minimum-year-value-in-sql-server.html

WCF

46. What is WCF also known as?
A. WCF (Windows Communication Foundation) is also know an Indigo by its code
name.

47. Difference between WCF and Web Services?
A. Below are the main differences between the WCF and Web Service:
Web Service:
a. Can be hosted in IIS only
b. Only two types of operations affects- One-Way, Request-Response
c. To serialize the data use System.Xml.Serialization
d. To encode the data use- XML 1.0, MTOM, DIME, Custom
WCF service:
a. Can be hosted in IIS, Self Hosting, WAS, Windows Services etc
b. Three types of operations affects- One-Way, Request-Response and Duplex
c. To serialize the data use System.Runtimel.Serialization
d. To encode the data use- XML 1.0, MTOM,Binary, Custom
e. WCF Service can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P
etc.

48. What are Endpoints?
A. The collection of Address, Binding and Contract is called as End Point. In Sort,
EndPoint = A+B+C
Address (Where)- it means where the service is hosted. URL of the service shows
the address.
Binding (How)- How to connect to the service, is defined by the Binding. It basically
has the definition of the communication channel to communicate to the WCF service
Contract (what)- It means what the service contains for the client. What all the
methods are implemented in the WCF service is implemented in the Contract.

49. What are Behavior and Bindings?
A. Binding mainly describes about the communication of the client and service. For
this, there are protocols corresponding to the binding behavior which will take care
of the communication channel. There are different protocols which we use for the
different types of bindings. E.g. HTTP, TCP, MSMQ, Named Pipes etc.
Behavior is used for the common configurations that could be for endpoints. When
we use the common behavior, they affect to all the end points. Adding the service
behavior affect the service related stuff while the endpoint related behavior affects
the end points. Also operations level behavior affects the operations.

50. What are different types of Contracts supported?
A. There are mainly 5 type of contracts used in WCF service:
a. Service Contract
b. Operation Contract
c. Data Contract
d. Message Contract
e. Fault Contract

51. What is the difference between Transport and Message Security mode?
A. WCF supports 2 types of security- Transport Level Security and Message Level
Security
Transport Level Security- In this type of security, we make the transport channel as
secure so that the data flows in that channel will be automatically secured. For
HTTP channel, we use the client certificate for the security of the web address. SSL
is used for the HTTP channel security. As we dont need to secure each of the
messages which are floating between the client and the service, the speed is faster
as direct message is going to the client from the service.
Message level security- This type of security in WCF is used where we dont have
the fixed transport medium and we need to secure each message which is floating
between the server and the client. In this type of security we use certain algorithms
for making the message as secure message. We use some extra bits and send with
the message. We also use some encryption techniques like SHA1 or MD5 which
make the proper security for our message. As each message needs to be secured,
this type of security makes some delay in the process of sending and receiving the
messages.

52. How to configure WCF security to support Windows authentication?
A. To support the WCF security in Windows Authentication, we need to add the
ClientCredetialType attribute to Windows under the security tab element:
transport clientCredentialType="Windows"

53. How to use Fault Contract?
A. Fault Contract is mainly used for viewing and displaying the errors which
occurred in the service. So it basically documents the error and the error message
can be shown to the user in the understandable way. We cant use here the
try.catch block for the error handling because the trycatch is the technology
specific (.Net Technology). So we use the Fault contract for the error handling.
e.g. To use the Fault contract, we can simply write like the below:
public int Add(int number1,int number2)
{
// write some implementation
throw new FaultException (Error while adding data..);
}
Here the fault Exception method is the inbuilt method which will throw the
exception and display the message . We can use the custom class so that the
message can be customized and the customized message can be sent to the client.
So we can creeat a clss like:
Public Class CustomException()
{
public int ID{get;set;}
public string Message{get;set;}

public string Type{get;set;}
}
Now this custom type we ca use with the Operation Contract as:
[ServiceContract]
Public interface IMyInterface
{
[OperationContract]
[FaultContract(typeOf(CustomException))]
Int Add(int num1,int num2);
}
Now while implementation of the Add method, we can assign the class properties.

WPF

54. Diff between XML and XAML.
A. XAML is the declarative XML based language which is used to define the objects
and properties. XAML document is loaded by XAML parser. So XAML Parser initiates
the objects and set those properties. XAML is mainly used in creating the objects in
WPF and Silverlight applications.
For more detailed explanation, you can go through the below link:
http://www.differencebetween.net/technology/software-technology/difference-
between-xml-and-xaml/

55. Stack Panel and Wrap Panel.
A. StackPanel is one of layout control in WPF. We can place the child controls inside
the stack panel either horizontally or vertically. So it provides two types of
orientations- Horizontal Orientation and Vertical orientation.
You can go through the below link for more detailed explanation and the code
snippet:
http://wpftutorial.net/StackPanel.html

Wrap panel is another layout control which is similar to the StackPanel. Wrap panel
not only keep the control in horizontal and vertical orientation but also wrap them
in to new line if there is no space. Here also the orientation can be set as
Horizontal or Vertical. Its main use is to arrange the tabs in the tab control, menu
control or in toolbar items.
You can go through the below link for more details:
http://wpftutorial.net/WrapPanel.html

56. Hierarchical Data Template.
A. Hierarchical Data Template is a type of data template which is used to bind the
controls which supports HeaderedItemsControl, like TreeViewItem or MenuItem
We can bind those controls items using the Hierarchical Data Template. It displayed
the data in to Hierarchical structure in the tree structure. It could be in the left to
right or top to bottom.
You can go through the below link for more details:
http://msdn.microsoft.com/en-us/library/system.windows.hierarchicaldatatemplate.aspx

57. Virtualization.
A. This is the feature in WPF which increases the efficiency of the programs when
there are the large data objects. If the WPF ItemsControl is bound with the large
collection data source object and we enabled the virtualization, then the controls
will show only the data which is in the visual container for those items which are
visible currently. This visual data is only the small part of the large data object.
Now when the user will scroll down or up, the rest of the data will be visible and
previous data will be hidden again. So this is increase the efficiency of the program
from the UI prospective.

58. Events and Routed Events.
A. Routed event is special type of event which can invoke and handle multiple
events from different objects rather than the event which is coming from one
object. So it generally handles the object from the element tree. So whatever the
elements inside the element tree and if they generate the event-may be multiple
events, the routed event is capable of handling those events.
The routed event can be invoked in both the directions but in general it comes from
the source element and then bubbled up in the element tree until the root element.

59. Bubbling and Tunneling.
A. Bubbling: When the events are raised form the innermost element in the visual
tree and comes up towards the root element, is called as bubbling.
Tunneling: It is the opposite process of Bubbling where the events fired by the root
element goes down towards the last child element control.
Please go through the below link for more details:
http://www.dotnetspider.com/forum/130497-event-bubbling-event-tunneling.aspx

60. Resource Dictionary, Static Resources and Dynamic Resources.
A. Static and Dynamic resources are used for binding the resources to the control
objects.
The main difference between StaticResource and DynamicResource is that how the
resource is retrieved elements. If the resource is StaticResource, it will be retrieved
only once by the element whoe is referencing it and it will be used for all the
resources. While the DynamicResource gets its value each time they reference to
the objects. So StaticResource is faster than the DynamicResource , because
StaticResource needs to get the value only once while the DynamicResource needs
each time to get it.

61. What is Prism?
A. Prism is the framework or the set of guidelines which is used to develop the WPF
desktop application as well as the Silverlight Rich Internet applications. So its a
kind of Design pattern to Develop the XMAL based application. It also used to
develop the Windows 7 applications. Prism mainly helps to design the loosely
coupled components which can be easily integrated with the other components of
the overall application. Prism mainly used to build the composite applications which
need various other components to be integrated.
Prism mainly guides of creating the applications using the Model-View-ViewModel
(MVVM) model, Managed Extensibility Framework (MEF), and navigation in the
application.
To use the Prism framework, we need to use their library called as Prism Library. So
prism Library is the inbuilt set of components which can be used in developing the
WPF and Silverlight applications.
You can go through the below link for more details and the use of the components
of the Prism framework:
http://msdn.microsoft.com/en-us/library/ff648465.aspx


62. Dependency Injection, Event Aggregator.
A. For the details about the dependency injection, you can follow the below link:
http://wpftutorial.net/ReferenceArchitecture.html
EventAggregator : It is the utility service which contains the events and allows the
decouple the publisher and subscriber so that they can be buildup independently.
Decouple is primarily useful when a new module needs to be added or removed or
modified. The new module can be added as per the event fired and defined in the
shell.
For more details about the Event Aggregator, you can follow the below link:
http://msdn.microsoft.com/en-us/library/ff921122(v=pandp.20).aspx

63. Shell, Bootstrapper and Region Managers
A. Bootstrapper:- An utility in WPF engine which is mainly responsible for the
initialization of the application by using the composite application library. By using
the bootstrapper we can find out how the components of the application are wired
up in the composite application library. The bootstrapper responsibility to create the
Shell or main window. Composite application library has the default abstract class
UnityBootstrapper which actually handles the initialization.
You can go through the below link for more details about the bootstrapper:
http://msdn.microsoft.com/en-us/library/ff921139(v=pandp.20).aspx
Region and Region Managers: This is concept of Prism framework. We define the
region through XAML code and once a region is defined, automatically it will be
registered with the RegionManager. Actually the Bootstrapper registers a service
called the RegionManager at run time. RegionManager is a dictionary where the key
is name of the region. The value of the key is the reference of the IRegion
interface. RegionAdapter is used to create the instance reference of the IRegion
interface.
You can go through the below link for more details about the Region and Region
Manager:
http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090091

64. What are MEF and Unity?
A. The MEF (Managed Extensibility Framework) is the new concept in .net 4.0. It is
used to create the lightweight and extensible applications to create Managed
Extensibility Framework. It is not only allows the extension but also reused within
the application. Extension can be easily encapsulating the code using the MEF.
For more details, you can go through the below link:
http://msdn.microsoft.com/en-us/library/dd460648.aspx

65. How to navigate to another page?
A. There is a class NavigationService which can be used for navigation of the WPF
window:
this.NavigationService.GoForward();
//or
this.NavigationService.Navigate("MysecondPage.xaml")


2+ yrs Experience .Net related Interview Questions and Answers for
Quick Reference
Hai Friends,
In the continuation of the series of the Interview Questions in
the Microsoft Technologies, I am posting few more questions which will be helpful
for the Quick reference in learning the concepts related to WCF, Assembly, SQL
Server,Interface & Abstract Class etc.

1. What is the difference between Web Services and WCF.
Ans.
A. WCF Services = Web Services + Remoting + Security + Reliability + Messaging
Queue
B. Not only that, hosting is also one of the powerful feature in WCF where the
service can be hosted in Self Hosting, Hosting in Windows Services, Hosting on
another Service etc.
C. Supports DataContractSerializer which is fast and can serialize fields and
properties.
D. Integrated Logging mechanism.

2. What are the different ways of hosting a WCF service.
Ans.
A. Hosting on Console application
B. Hosting on Windows application
C. Hosting on Windows services
D. Hosting on IIS
E. Hosting on WAS(Windows Activation Service)

3. Explain the different types of triggers in SQL Server.
Ans.
A. DDL Trigger- Trigger fires on DDL Commands
B. DML Trigger- Trigger fires on DML Commands
C. InsteadOf Trigger- Trigger fires on View updation

4. Difference between BasicHttpBinding and WSHttpBinding.
Ans.
A. BasicHttpBinding does not enable message level security while the
WSHttpBinding enables Message level as well as Transport level security.
B. BasicHttpBinding has the default windows authentication while the
WSHttpBinding support WS* authentication and security.
C. BasicHttpBinding only supports HTTP to access the service while WSHttpBinding
suppors HTTP and HTTPS(secure)
D. Data which travels through the BasicHttpBinding is in XML format and no
encryption allowed while the data travels through WSHttpBinding goes in Encrypted
format.

5. What are the different types of assemblies available in .NET?
Ans.
A. Private Assembly
B. Shared Assembly
C. Satellite Assembly

6. What is a strong name and how do you give a strong name to an
assembly?
Ans.
Unique identification of an assembly called as strong name. By strong name we can
differentiate the assemblies which are having the same name.
We can generate the Strong name using the command:
SN -K dllName
7. What is InsteadOf trigger.
Ans.
To update the Views, InsteadOf trigger is used. This is the only use of InsteadOf
trigger. There is no use except this.

8. Can we use Insert/Update statements in views in SQL SERVER?
Ans.
No, View works only on the Query/select command. So we can't have DML
commands inside the View. So no Insert/update operations are allowed.

9. What are abstract classes and Interface and what the difference
between the two.
Ans.
When the class does not provides the full functionality, the class must be declared
as the abstract class.
There are 2 types of abstract classes-
A. Partial Abstract Class (Abstract Class)- Class which can support the abstract
members(methods, properties) as well as concrete members(methods, properties),
the class can be declared as the abstract class.
Abstract class works based on the child class memory. We can't create the object of
the abstract class, only the reference can be created for the abstract class.
All the abstract members must be overrides in the child class using the Override
keywords.

B. Fully Abstract class (Interface) - The collection of abstract members
(methods, properties) is called as interface.
Interface contains all the abstract members.

When you have limited scope for the functionality, Abstract class is better
but when there is the requirement to implement the global functions,
interface is best way to do.
e.g. When u have some feature which can be implemented in several classes and
classes are interrelated, use Abstract class but when the feature can be application
level and used by various independent classes, use Interface.

10. What are the advantages of Interface over abstract classes?
Ans.
When you have some feature which can be implemented in several classes and
classes are interrelated, use Abstract class but when the feature can be application
level and used by various independent classes, use Interface.
Interfaces are more rigid than Abstract classes.
e.g. let's say, i have a method called Show() to show the message in various
classes, we can have interface for this. Now let's say, I have implemented this
interface in 100 classes where I want to use the Show() method to show some
message.
Tomorrow there is some requirement to have the new Print Functionality to let's
say in 50 various classes. Now the one way is to add this Print() in the same
interface so that we can just implement it to those classes. But what about the rest
50, where we don't want this print.. So this is drawback of Interface.
That is the reason the Single Responsibility principle and then the interface
Segregation Principle came where a class/interface should have only one
responsibility. Like in the above example, there are more responsibility and got the
problem.
Abstract class is best when the scope is limited. Let's say I want to calculate the
Area of few shapes. So we can say that this is limited as few classes can use this so
we can create the abstract class with the abstract method called Area and then
implement to those classes by inheriting the abstract class.
The scope of the Abstract class is till the immediate child class. So you can't use it
in grand child or grandparent classes.

11. What is a sealed class?
Ans.
When the class provides full functionality, we can declare the class as Sealed Class.
Full functionality means, the class doesn't need anything from outside like loading
the external files etc. The sealed class cant be inherited and can't be extended. We
can create the object of sealed class so instantiation of the sealed class is
possible.when the class is self-dependent, the class be made as sealed class.
Overall when we want the class prevented to be inherited, we can declare the class
as sealed class. Also If we want that our method should not be overridable, we can
create the methods as sealed method.
E.g.If you see the definitions of the datatypes, they all are sealed by default
becasue they cant be extended.
public sealed class String : IComparable, ICloneable, IConvertible,
IComparable<string>, IEnumerable<char>, IEnumerable, IEquatable<string>
{
// Summary:
// Represents the empty string. This field is read-only.
public static readonly string Empty;

// Summary:
// Initializes a new instance of the System.String class to the value indicated
// by a specified pointer to an array of Unicode characters.
//
// Parameters:
// value:
// A pointer to a null-terminated array of Unicode characters.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// The current process does not have read access to all the addressed
characters.
//
// System.ArgumentNullException:
// value is null.
//
// System.ArgumentException:
// value specifies an array that contains an invalid Unicode character, or value
// specifies an address less than 64000.
[CLSCompliant(false)]
[SecurityCritical]
public String(char* value);
....
Here we can see that String class is of Sealed type.We can create the object of the
sealed class as:
String obj = new String();
bu we cant inherit these classes as they are not inheritable.


12. What kind of authentication mechanism you have used in your WCF
project.
Ans.
There are various authentication modes which can be used for the WCF service like-
A. No Authentication- When the service doesn't requires any authentication and
its public to access and use, this type of authentication mode is used.
B. Windows Authentication This type of service depends on the windows
credential so if the user is having the windows credentials, they can use and access
the service.
C. Form Authentication This type of authentication requires certain and valid
user name and password to access the service.
D. Certificate Based There are the secure cervices where each request needs
certain authentication mechanism which can be the 3rd party like .X509 certificates
to validate the access requests.
E. Custom Authentication- This can be mixed with two or more authentication
mechanism.
F. Token Based Authentication Depends on the token provided by the service
provider. So based on the token, the client can access the service.

13. How do you configure a WCF Service to use Network Authentication?
Ans.
We need to set the remote settings for this.
Below is the reference url:
http://technet.microsoft.com/en-us/library/cc742824.aspx
14. What is Garbage Collection? How is Garbage Collector invoked in .NET?
Ans.
When the heap memory is filled with the objects and there is no memory left to
accommodate the new object, Garbage collector gets called by the CLR. So it's an
activity which is initiated by the run time (CLR). When the garbage collector gets
called, it tries to find out each referenced objects which are in use by the
applications. The objects which are not reachable, it marks them to delete. Based
on the reachable objects, the garbage collector prepares the object graph, which
has the reference of each reachable object. Now based on the object graph which
contain the object generations too, the Garbage collector checks for the generation
0 objects and marks them for deletion and move rest of the objects to generation
1. The heap memory gets compacted for the new object and new object gets placed
in the heap memory.
This is the uncertain and un-deterministic process as the Garbage collector doesn't
know when it will be called. Its all based on the capacity memory of the heap.
When the heap memory get filled and a new object is initiated, the runtime (CLR)
calls the Garbage collector.

15. Can you force Garbage Collector to be invoked from c# code?
Ans.
Yes, When we have something called the unmanaged objects(C++, VC++,VB 6.0),
then we need to explicitly release the memory. To do this, we can use the
Dispose() method to free-up these object.
Sometimes, we need to force the garbage collector to be called to free-up the
memory, so we can use the GC.Collect() method to do so.

16. How is var keyword used in .NET.Difference between var and dynamic
keywords.
Ans.
var keyword is newly introduces with the .net 3.5 and it is used to make the
assignment for any type of data. It can store any type of data irrespective of its
datatype.
So when we don't know that what type of data, the certain process will return, we
can use the var keyword.
e.g.
var connection = new SqlConnection(connectionString);
Here the connection variable can store the SQLConnection type.
Dynamic keyword is newly introduces with the .net 4.0 version and is used to keep
not only the any type of data but also the reference will be constant.
For the var, the type is made at the compile time while in case of Dynamic; the
type is inferred in runtime.
e.g.
var customer = new Customer();
customer.GetCustomers();
Here the compiler will check for the GetCustomers()method. If the GetCustomers()
method doesn't exists, it will show error during the compilation.
But for the dynamic,
dynamic customer = new Customer();
customer.GetCustomers();
Here the compiler will not check for the GetCustomers() method during the
compilation. But at the run-time, if the method is not available, it will throw error.
So the main use of dynamic is when we don't want the compiler should check for
certain errors during compilation. It will skip the error if they are of dynamic type.

17. Difference between Stored Procedures and Functions.
Ans.
Stored Procedure and Functions are the database objects which are the pre-
compiled names SQL statements.
A. Stored procedure can take in as well as Out parameters while function can take
only in parameters'.
B. Stored Procedure may or may not return the value while the Function must
return a value. Returning a value in stored procedure depends on the input
parameter. If the input parameter is of type out, then it will return the value.
C. We can use the function inside the stored procedure but stored procedure can't
be used inside a function.

18. What are the different types of contracts available in WCF
Ans.
A. Service Contract- In Interface
B. Operation Contract - For Operations
C. Data Contract -Based on custom type
D. Message Contract - For Custom message
E. Fault Contract - For Error or Exception Handling

19. What is the static variable and what are the static variables in dot net.
Ans.
When the variable is shared by multiple class members (method, properties etc),
we can make that variable as Static (in VB.Net Shared). To access these variables,
we don't need to create the object of the class. We can directly call the static class
members using the Class name. These variables get loaded when the class gets
loaded in to the memory.
20. If I have 2 interfaces with same method same parameter and same
return type. Both interface implemented from one Class. Then how can i
call to these methods.
Ans.
Two interfaces with the same methods and same parameters can be implemented
using the external interface functionality, rather than internal interface.
By default, when we implement the interface, we need to implement all the method
to the implemented class.
But if the methods are same, then we can take the help of explicit interface as:
interface inf1
{
void Print();
void Show();
}
interface inf2
{
void Print();
void Show();
}
Now we will implement these interfaces in a single class:
class MyChildClass: inf1, inf2
{
public void inf1.Print() // explicit interface call
{
//implement Print() method details for the first interface
}
public void inf1.Show()
{
//implement Show() method details for the first interface
}
public void inf2.Print()
{
//implement Print() method details for the second interface
}
public void inf2.Show()
{
//implement Show() method details for the second interface
}
}
21. Can method overloading and overriding possible in simultaneously in
program.
Ans.
Yes, both overloading and overriding concept can be implemented simultaneously
between the parent can child classes as:
Class MyBaseClass
{
public void Print()
{
// Print method implementation
}
public void Print(string fileName) // overloaded method
{
// Print method implementation with the file name
}
public virtual void Print()
{
// Print method implementation
}
}
Class ChildClass:MyBaseClass
{
public override void Print() // overriding implementation
{
// Print method implementation
}
}

22. What is "using" keyword?
Ans.
"using" keyword is used in 2 scenarios:
1. To write the namespace as:
using System.Data.SqlClient;
2. To clean up the memory automatically after the use of object as:
using(var f = new SqlCommand())
{
// some other iomplementation
}
The above code will delete the memory used by the 'f' object after the completion
of the transaction.

23. What is dispose and finalize method and how it works
Ans.
Finalize and Dispose methods comes under the System.GC namespace and used to
free up the memory occupied the objects. Garbage collector uses these objects to
free up the memory.
When there is no enough memory to allocate the new object in the Heap, Garbage
collector gets called automatically to free up the memory. It mainly creates the
object graph and finds the objects which are not used since longer time. Based on
the generations, it removes the objects.
Dispose method is called manually by programmer to remove the objects.
It uses IDisposable interface which has the Dispose method and this can be
implemented in the code.



ASP.Net Interview Question and Answer for 2+ or 3+ years experience
1.) What is asp.net life cycle ?
Life Cycle Events

PreInit

The properties like IsPostBack have been set at this time.

This event will be used when we want to:
1. Set master page dynamically.
2. Set theme dynamically.
3. Read or set profile property values.
4. This event is also preferred if want to create any dynamic controls.
Init
1. Raised after all the controls have been initialized with their default values and
any skin settings have been applied.
2. Fired for individual controls first and then for page.
LoadViewState
1. Fires only if IsPostBack is true.
2. Values stored in HiddenField with id as _ViewState decoded and stored into
corresponding controls.
LoadPostData

Some controls like:
1. Fires only if IsPostBack is true.
2. Some controls like Textbox are implemented from IPostBackDataHandler and
this fires only for such controls.
3. In this event page processes postback data included in the request object
pass it to the respective controls.
PreLoad
Used only if want to inject logic before actual page load starts.
Load
Used normally to perform tasks which are common to all requests, such as
setting up a database query.
Control events
1. This event is fired when IsPostBack is true.
2. Use these events to handle specific control events, such as a Button control's
Click event or a TextBox control's TextChanged event.
PreRenderRaised after the page object has created all the controls that are
required for rendering which includes child controls and composite controls.
1. Use the event to make final changes to the contents of the page or its
controls before the values are stored into the viewstate and the rendering
stage begins.
2. Mainly used when we want to inject custom JavaScript logic.
SaveViewState
All the control values that support viewstate are encoded and stored into the
viewstate.
RenderGenerates output (HTML) to be rendered at the client side.
We can add custom HTML to the output if we want here.
Unload
1. Fired for individual controls first and then for page.
2. Used to perform cleanup work like closing open files and database
connections.


2.) How the request is handled by IIS ?

We give an URL to an aspx page in the browser address bar and press enter. What
happens next? We get the response in terms of rendered HTML but how?
1. We are requesting something from the browser, which means indirectly we
are requesting something from the Web Server, that means IIS. IIS, based
on the file extension, decides which ISAPI extension can serve the request.

And in case of ASP.Net (.aspx) it will be aspnet_isapi_dll so the request is
passed to it for processing.

2. When the first request comes to the website,

an application domain is created by the ApplicationManager class where
exactly the website runs, and which creates an isolation between 2 web
applications.
Within the application domain an instance of the HostingEnvironment class is
created which provides access information about the application such as the
name of the folder where the application is stored.

3. Next ASP.Net creates core objects like HttpContext,
HttpRequest,HttpResponse.

4. Finally the application starts by creating an instance of the HttpApplication
Class (which can be reused for multiple requests to maximize performance).
3.) What is Difference between Session and Cookies ?

The basic and main difference between cookie and session is that cookies are
stored in the user's browser but sessions can't store in user's browser. This
specifies which is best used for.

A cookie can keep all the information in the client's browser until deleted. If a
person has a login and password, this can be set as a cookie in their browser so
they do not have to re-login to your website every time they visit. You can store
almost anything in a browser cookie.

Sessions are not reliant on the user allowing a cookie. They work like a token in
the browser which allowing access and passing information while the user has
opened his browser. The problem in sessions is when you close the browser the
session will automatically lost. So, if you had a site requiring a login, this couldn't
be saved as a session but it can be saved as a cookie, and the user has to re-login
every time they visit.
cookies are nothing but a small piece of information on the client machine. before
we create a cookies we should check whether the cookies are allowed at the
browser side. They are limited in a size 4k.(they are 2 types of cookies peristant
cookie , and session cookies)

Sessions cookies are stored in a server memory during the client browser
session.When the browser is closed the session cookies are lost.


4.) Advantages and disadvantages of Session?

Following are the basic advantages and disadvantages of using session. I have
describe in details with each type of session at later point of time.
Advantages:
It helps maintain user state and data all over the application.
It is easy to implement and we can store any kind of object.
Stores client data separately.
Session is secure and transparent from the user.
Disadvantages:
Performance overhead in case of large volumes of data/user, because
session data is stored in server memory.
Overhead involved in serializing and de-serializing session data, because in
the case of StateServer and SQLServer session modes, we need to serialize
the objects before storing them.
Besides these, there are many advantages and disadvantages of session that are
based on the session type. I have discussed all of them in the respective sections
below.

5). What is state management?
Ans: State management is the process by which you maintain state and page
information over multiple requests for the same or different pages.

6). Http is stateless, What does this mean?
Ans: Stateless protocol is a communications protocol that treats each request as an
independent transaction that is unrelated to any previous request so that the
communication consists of independent pairs of requests and responses.

7). What is Session?
Ans: We know that Http is stateless, means when we open a webpage and fill some
information and then move to next page then the data which we have entered will
lost.
It happed do to Http protocol stateless nature. So here session come into existence,
Session provide us the way of storing data in server memory. So you can store
your page data into server
memory and retrieve it back during page postbacks.

8). What are the Advantage and disadvantage of Session?
Ans: Advantages:
Session provide us the way of maintain user state/data.
It is very easy to implement.
One big advantage of session is that we can store any kind of object in it. :eg,
datatabe, dataset.. etc
By using session we don't need to worry about data collesp, because it store every
client data separately.
Session is secure and transparent from the user.
Disadvantages:
Performance overhead in case of large volumes of data/user, because session data
is stored in server memory.
Overhead involved in serializing and de-serializing session data, because in the case
of StateServer and SQLServer session modes, we need to serialize the objects
before storing them.

9). What is Session ID in Asp.net?
Ans: Asp.Net use 120 bit identifier to track each session. This is secure enough and
can't be reverse engineered. When client communicate with server, only session id
is transmitted, between them. When client request for data, ASP.NET looks on to
session ID and retrieves corresponding data.

10). By default where the sessions ID's are stored ?
Ans: By default, the unique identifier for a session is stored in a non-expiring
session cookie in the browser. You can specify that session identifiers not be stored
in a cookie by setting the cookieless attribute to true in the sessionState
configuration element.
We can also configure our application to store it in the url by specifying a
"cookieless" session
The ASP Session cookie has this format:-
ASPSESSIONIDACSSDCCC=APHELKLDMNKNIOJONJACDHFN


11). Where does session stored if cookie is disabled on clients machine?
Ans: If you want to disable the use of cookies in your ASP.NET application and still
make use of session state, you can configure your application to store the session
identifier in the URL instead of a cookie by setting the cookieless attribute of the
sessionState configuration element to true, or to UseUri, in the Web.config file for
your application.
The following code example shows a Web.config file that configures session state to
use cookieless session identifiers.

Code:
<configuration>
<system.web>
<sessionState
cookieless="true"
regenerateExpiredSessionId="true"
timeout="30" />
</system.web>
</configuration>

12). Can you describe all the property set in web.config under session
state?
Ans:
Code:
<configuration>
<sessionstate
mode="inproc"
cookieless="false"
timeout="20"
sqlconnectionstring="data source=127.0.0.1;user id=<user
id>;password=<password>"
server="127.0.0.1"
port="42424"
/>
</configuration>
Mode: The mode setting supports three options: inproc, sqlserver, and stateserver.
As stated earlier, ASP.NET supports two modes: in process and out of process.
There are also two options for out-of-process state management: memory based
(stateserver), and SQL Server based (sqlserver). We'll discuss implementing these
options shortly.
Cookieless: The cookieless option for ASP.NET is configured with this simple
Boolean setting.
Timeout: This option controls the length of time a session is considered valid. The
session timeout is a sliding value; on each request the timeout period is set to the
current time plus the timeout value
Sqlconnectionstring: The sqlconnectionstring identifies the database connection
string that names the database used for mode sqlserver.
Server: In the out-of-process mode stateserver, it names the server that is running
the required Windows NT service: ASPState.
Port: The port setting, which accompanies the server setting, identifies the port
number that corresponds to the server setting for mode stateserver.

13). What are Session Events?
Ans: There are two types of session events available in ASP.NET:
Session_Start
Session_End
You can handle both these events in the global.asax file of your web application.
When a new session initiates, the session_start event is raised, and the
Session_End event raised when a session is abandoned or expires.

14). How you can disable session?
Ans: If we set session Mode="off" in web.config, session will be disabled in the
application. For this, we need to configure web.config the following way:
Code:
<configuration>
<sessionstate Mode="off"/>
</configuration>

15). If I have more than one version of one assemblies, then how will I use
old version (how/where to specify version number?) in my application?

Ans.The version number is stored in the following format: . The assembly
manifest can then contain a reference to which version number we want to use.

16). How do you create threading in.NET? What is the namespace for that?
Ans.
System.Threading;

//create new thread using the thread classs constructor

Thread myThread = new Thread(new ThreadStart (someFunction));

17). What do you mean by Serialize and MarshalByRef?

Serialization is the act of saving the state of an object so that it can be recreated
(i.e deserialized) at a later date.
The MarshalByRef class is part of the System.Runtime.Remoting namespace and
enables us to access and use objects that reside in different application
domains. It is the base class for objects that need to communicate across
application domains. MarshalByRef objects are accessed directly within their own
application domain by using a proxy to communicate. With MarshalByValue the a
copy of the entire object is passed across the application domain

18). What is the difference between Array and LinkedList?
An array is a collection of the same type. The size of the array is fixed in its
declaration.
A linked list is similar to an array but it doesnt have a limited size.

19). What is Asynchronous call and how it can be implemented using
delegates?

A synchronous call will wait for a method to complete before program flow is
resumed. With an asynchronous call the program flow continues whilst the method
executes.

//create object
SomeFunction objFunc = new SomeFunction();

//create delegate
SomeDelegate objDel = new SomeDelegate(objFunc.FunctionA);

//invoke the method asynchronously (use interface IAsyncResult)
IAsyncResult asynchCall = SomeDelegate.Invoke();

20). How to create events for a control? What is custom events? How to
create it?
Ans.
An event is a mechanism used in a class that can be used to provide a notification
when something interesting happens. (typical evens in a windows application
include: change text in textbox, double click or click a button, select an item in
dropdown box).
A custom event is an event created by the user that other developers can use. For
example assuming that we have a CashTransaction class and we have a bank
balance property in that class. We may want to set-up an event that provides a
notification when the bank balance drops below a certain amount. In order to
produce an event the process would be roughly as follows:
Create the class for the event derived from EventArgs.
Create a delegate with a return type of void.
Create a class containing the method that will activate the event.
Create a class with methods to handle the event.

21). If you want to write your own dot net language, what steps you will
you take care?

We will need to ensure that the high level code is compiled to MSIL (Microsoft
intermediate language) so that it can be interpreted by the CLR.

22). Describe the diffeerence between inline and code behind - which is
best in a loosely coupled solution?

The term code behind refers to application code that is not embedded within the
ASPX page and is separated out into a separate file which is then referenced
from the ASPX page. Inline code is the traditional ASP architectural model where
business logic code was embedded within the ASP page. Separating the business
logic code from the presentation layer offers several advantages:
1) It allows graphic designers and web developers to work on the presentation layer
whilst the application developers concentrate on the business logic.
2) The codebehind file is compiled as a single dll increasing the efficiency of the
application,
3) The codebehind model offers a true OO development platform,
4) It speeds up development time as it allows developers to fully maximise the
features of the .NET framework such as Cahing, ViewState, Session, Smart
Navigation etc.
5) Code is much easier to maintain and susceptible for change.
6) The compiler and VS.NET provides much better support for error checking,
intellisense and debugging when using the code behind model.

23). How dot net compiled code will become platform independent?

The raison detre for .NET was to cater for multiples languages on a single windows
platform whereas the aim of Java was to be a single language on multiple
platforms. The only way that .NET can be platform independent is if there is a
version of the .NET framework installed on the target machine.

24). Without modifying source code if we compile again, will it be
generated MSIL again?

Ans.No.

25). How does you handle this COM components developed in other
programming languages in.NET?

Ans.
use TlbImp.exe to import the COM types into your .NET project. If no type library
for the COM component then use System.Runtime.InteropServices
use RegAsm.exe to call a .NET developed component in a COM application.

26). How CCW (Com Callable Wrapper) and RCW (Runtime Callable
Wrappers) works?

CCW: When a COM application calls a NET object the CLR creates the CCW as a
proxy since the COM application is unable to directly access the .NET object.
RCW: When a .NET application calls a COM object the CLR creates the RCW as a
proxy since the .NET application is unable to directly access the .COM object.

27). What are the new thee features of COM+ services, which are not
there in COM (MTS)?

Role based security.
Neutral apartment threading.
New environment called context which defines the execution environment

28). What are the differences between COM architecture and.NET
architecture?

.Net architecture has superseded the old COM architecture providing a flexible rapid
application development environment which can be used to create windows,
web and console applications and web services. .NET provides a powerful
development environment that can be used to create objects in any .NET compliant
language.
.NET addresses the previous problems of dll hell with COM by providing strongly
named assemblies and side-by-side execution where two assemblies with the same
name can run on the same box.

29). Can we copy a COM dll to GAC folder?

Ans.
No. It only stores .NET assemblies.

30). What is Shared and Repeatable Inheritance?

Shared Inheritance-: Shared Inheritance-: ITt is multiple times using same class.
The mechanism of deriving a new class from an existing class is called inheritance.
Shared inheritance introduces a new opportunity of ambiguity and additional
implementation complexity. Assume D inherits from B and C, both of which inherits
from A. Here A in shared. Single copy made from both derived classes is called
shared inheritance.

31). Can you explain what inheritance is and an example of when you
might use it?

Ans.
Inheritance is a fundamental feature of any OO language. It allows us to inherit the
members and attributes from a base class to a new derived class. This
leads to increased code reusability and also makes applications easier to develop,
maintain and extend as the new derived class can contain new features not
available in the base class whilst at the same time preserving the attributes
inherited from the base class.

32). How can you write a class to restrict that only one object of this class
can be created (Singleton class)?

Ans.
Use the singleton design pattern.
public sealed class Singleton
{
static readonly Singleton Instance=new Singleton();
static Singleton()
{
}
Singleton()
{
}
public static Singleton Instance
{
get
{
return Instance;
}
}
}
33). What are virtual destructures?


A constructor can not be virtual but a destructor may. Use virtual destructors when
you want to implement polymorphic tearing down of an object.

34). What is close method? How its different from Finalize and Dispose?

finalise is the process that allows the garbage collector to clean up any unmanaged
resources before it is destroyed.
The finalise method can not be called directly; it is automatically called by the CLR.
In order to allow more control over the release of unmanaged resources
the .NET framework provides a dispose method which unlike finalise can be called
directly by code.
Close method is same as dispose. It was added as a convenience.

35). What is Boxing and UnBoxing?

Ans.
Boxing is the process of converting a value type to a reference type. More
specifically it involves encapsulating a copy of the object and moving it from
stack to heap. Unboxing is the reverse process.

36). What is check/uncheck?

Ans.
checked: used to enable overflow checking for arithmetic and conversion functions.
unchecked: used to disable overflow checking for arithmetic and conversion
functions

37). What is the use of base keyword? Tell me a practical example for
base keywords usage?

Ans.
The base keyword is used to access members of the base class from within a
derived class:
* Call a method on the base class that has been overridden by another method.
* Specify which base-class constructor should be called when creating instances of
the derived class.

A base class access is permitted only in a constructor, an instance method, or an
instance property accessor.
It is an error to use the base keyword from within a static method.
Example:In this example, both the base class, Person, and the derived class,
Employee, have a method named Getinfo. By using the base keyword,
it is possible to call the Getinfo method on the base class, from within the derived
class.
// keywords_base.cs
// Accessing base class members


using System;
public class Person
{
protected string ssn = "444-55-6666";
protected string name = "John L. Malgraine";
public virtual void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("SSN: {0}", ssn);
}
}
class Employee: Person
{
public string id = "ABC567EFG";
public override void GetInfo()
{
// Calling the base class GetInfo method:
base.GetInfo();
Console.WriteLine("Employee ID: {0}", id);
}
}
class TestClass {
public static void Main()
{
Employee E = new Employee();
E.GetInfo();
}
}



38). Difference Between Query String and Session

Querystring Session
Querystring is client side state management technique.
Session is server side state management
technique.
Querystring data is page specific i.e. can be accessed in
that page only.
Session data can be accessed throughout the
session.
Querystring data is visible to user and can be seen in
browser url.
Session data is not visible to user.
Data is not secured and can be altered hence insensitive
data is stored in querystring.
Data is secured hence sensitive data such as
user information is stored.
Querystring has constraint of Maxlength. Session does not have such constraint.

39). Difference between Query string and Cookies
cookies is a text file stored on client machine when we surf ant thing on internet
by the server automatically we dont have to create it

query string is used to transfer data from 1 page to anothe but this is not safe s it
shows in url what data we r sending
pen any site and see url after question mark tht is url

Cookies: - Cookies are little pieces of information that a server stores on a
browser. They are of two types
1. Temporary cookie
2. Persistent cookie

Temporary cookie: - They are also known as session cookies. These are volatile in
nature. When the browser is shutdown they are erased.

Persistent cookie:- These may be called as permanent cookies. These are especially
saved in files. It may remain for a month or year.
Properties of cookies
Some properties of cookie
Name: - represent the name of cookie.
Name value: - represent a collection of key values of cookie
Domain: - represent the domain associated with a specific cookie.
Path: - the path associated with a cookie.
Expires: - expired time of cookie.
Hashkey: - identifies whether the cookie is a cookie dictionary.
Secure: - specifies whether the cookie is to be sent in an encrypted connection or
not
Query string is the limited way to pass information to the web server while
Transferring from one page to another page. This information is passed in url of the
request. see below the code sample


Code Sample

//Retrieving values from query string
String name;
//Retrieving from query string
name = Request.Param["umar"].ToString();

But remember that many browsers impose a limit of 255 characters in query
strings. You need to use HTTP-Get method to post a page to server otherwise query
string values will not be available.

40). How can we identify that the Page is Post Back?
Page object has an "IsPostBack" property, which can be checked to know that is the
page posted back.

41). What is the lifespan for items stored in ViewState?
PThe items stored in ViewState live until the lifetime of the current page expires
including the postbacks to the same page
42). What is AutoPostBack?
If you want a control to postback automatically when an event is raised, you need
to set the AutoPostBack property of the control to True
43). Why do you use the App_Code folder in ASP.NET?
The App_Code folder is automatically present in the project. It stores the files, such
as classes, typed data set, text files, and reports. If this folder is not available in
the application, you can add this folder. One of the important features of the
App_Code folder is that only one dll is created for the complete folder, irrespective
of how many files it contains.
44). In which event of page cycle is the ViewState available?

After the Init() and before the Page_Load().
45). How long the items in ViewState exists?
They exist for the life of the current page.

46). Where the viewstate is stored after the page postback?

ViewState is stored in a hidden field on the page at client side. ViewState is
transported to the client and back to the server, and is not stored on the server or
any other external source.

47). What are the different Session state management options
available in ASP.NET?

1. In-Process
2. Out-of-Process.
In-Process stores the session in memory on the web server.

Out-of-Process Session state management stores data in an external server. The
external server may be either a SQL Server or a State Server. All objects stored in
session are required to be serializable for Out-of-Process state management.
48). What is the difference between web config and machine config?
Web config file is specific to a web application where as machine config is specific to
a machine or server. There can be multiple web config files into an application
where as we can have only one machine config file on a server.
49). What are the different types of cookies in ASP.NET?
Session Cookie Resides on the client machine for a single session until the user
does not log out.
Persistent Cookie Resides on a users machine for a period specified for its
expiry, such as 10 days, one month, and never.
50). What is the difference between ExecuteScalar and
ExecuteNonQuery?
ExecuteScalar returns output value where as ExecuteNonQuery does not return any
value but the number of rows affected by the query. ExecuteScalar used for
fetching a single value and ExecuteNonQuery used to execute Insert and Update
statements.


OOPs Concepts: When to use
Hai Friends,

This post is regarding the main OOPs concepts and what is there use and when its good to
use them.

Below are the concepts which are included in this post:

Encapsulation
Abstraction
Overloading
Method Overriding
Constructor
Interface
Inheritance
Abstract class

These OOPs concepts you can use while implementing the functionality of your projects
in accordance with the requirements and situations.
Hope it will be useful to learn and in the implementation of the projects.
1) In which situation encapsulation is used in your project?
Accessing the public properties by using private variables is one of the good examples of
Encapsulation in all the projects.
e.g.
private string _name;
public String Name
{
get{return _name}
set{_name= value;}
}

Here you are not able to access the private variable _name but its value can be accessible
by the public property Name. So a kind of Encapsulation here.
2) In which situation abstraction is used in your project?
When there are the specific requirements and that can be flown to their child, then we can
use abstraction. it means whatever is essential, we implement to its child classes, else will
be inherited automatically.
e.g.
class A
{
public abstract void Add(int a, int b);
protected int x;
public string Name{get; set;};
}
Class B: A
{
public override void Add(int a, int b)
{
Console.WriteLine("Sum of two numbers is:" + int. Parse(a + b).toString());
}
}
Here the essential method Add is implemented to the child class B. rest all the members will
be inherited accordance to their protection levels.

3) In which situation method overloading is used in your project?
When we have more functionality to implement, we go with the overloading of method.
e.g. we have to get the sum of 2 numbers, 3 number and 4 numbers. So in that case we
can take only one method name Add with its varied parameters like:

public void Add(int a, int b)
{
Console.WriteLine("Sum of 2 numbers" + int. Parse(a + b).toString());
}

public void Add(int a, int b, int c)
{
Console.WriteLine("Sum of 3 numbers" + int. Parse(a + b +c).toString());
}

public void Add(int a, int b, int c, int d)
{
Console.WriteLine("Sum of 4 numbers" + int. Parse(a + b + c +
d).toString());
}

Now according to our requirement, we can call the respective method with its arguments.

4) In which situation method overriding is used in your project?
When we may or may not want to implement the particular method at runtime to its child
class according to the requirement, we go with overriding concept.
e.g.
Class X
{
public virtual void Print()
{
Console.WriteLine ("This is the print method. You can override according to
your definitions and implementation");
}
}
Class Y:X
{
public Override void Print()
{
Console.WriteLine("Implementation for Excel print methods");
}
}

5) In which situation constructor is used in your project?
Constructor is by default initialize with the class.
But if you want to initialize some members when the class in getting instantiate, you can
write the constructor and code for initialization inside that constructor.
e.g.
Class MyClass
{
public MyClass()
{
int a=10; //initialized with the class instantiation
}
}

Here the constructor code will get initialized with the class instantiation.
6) In which situation interface is used in your project?
Interface is the collection of abstract members.
So whenever we have the requirements such as it requires through the application at many
places, then we create an interface with that method so that we can implement it at our
own way according to the requirements.
e.g.
Interface Inf
{
void Print();
}

Class ExcelClass:Inf
{
public override void Print()
{
//Write code to print in excel
}
}

Class WordPrintClass: Inf
{
public override void Print()
{
//Write code to print in Word
}
}
Class PDFPrintClass: Inf
{
public override void Print()
{
//Write code to print in PDF
}
}

Also to implement the multiple inheritances, we use inheritance.

7) In which situation inheritance is used in your project?
When we want to have some common features for multiple classes then we go for
inheritance.
To inherit the properties of base class to their derived class.
8) In which situation abstract class is used in your project?
Abstract class is same as abstract. So go to the Q 2 for the details.

1) In which situation encapsulation is used in your project?

Accessing the public properties by using private variables is one of the good examples of
Encapsulation in all the projects.
e.g.

private string _name;
public String Name
{
get{return _name}
set{_name= value;}
}

Here you are not able to access the private variable _name but its value can be accessible by the
public property Name. So a kind of Encapsulation here.

2) In which situation abstraction is used in your project?

When there are the specific requirements and that can be flown to their child, then we can use
abstraction. it means whatever is essential, we implement to its child classes, else will be
inherited automatically.
e.g.

class A
{
public abstract void Add(int a, int b);
protected int x;
public string Name{get; set;};
}
Class B:A
{
public override void Add(int a, int b)
{
Console.WriteLine("Sum of two numbers is:" + int. Parse(a + b).toString());
}
}

Here the essential method Add is implemented to the child class B. rest all the members will be
inherited accordance to their protection levels.

3) In which situation method overloading is used in your project?

When we have more functionality to implement, we go with the overloading of method.
e.g. we have to get the sum of 2 numbers, 3 number and 4 numbers. So in that case we can take
only one method name Add with its varied parameters like:

public void Add(int a, int b)
{
Console.WriteLine("Sum of 2 numbers" + int. Parse(a + b).toString());
}

public void Add(int a, int b, int c)
{
Console.WriteLine("Sum of 3 numbers" + int. Parse(a + b +c).toString());
}

public void Add(int a, int b, int c, int d)
{
Console.WriteLine("Sum of 4 numbers" + int. Parse(a + b + c +
d).toString());
}
Now according to our requirement, we can call the respective method with its
arguments.


4) In which situation method overriding is used in your project?

When we may or may not want to implement the particular method at runtime to its child class
according to the requirement, we go with overriding concept.
e.g.

Class X
{
public virtual void Print()
{
Console.WriteLine ("This is the print method. You can override according to
your definitions and implementation");
}
}
Class Y:X
{
public Override void Print()
{
Console.WriteLine("Implementation for Excel print methods");
}
}


5) In which situation constructor is used in your project?

Constructor is by default initialize with the class.
But if you want to initialize some members when the class in getting instantiate, you can write
the constructor and code for initialization inside that constructor.
e.g.

Class MyClass
{
public MyClass()
{
int a=10; //initialized with the class instantiation
}
}

Here the constructor code will get initialized with the class instantiation.

6) In which situation interface is used in your project?

Interface is the collection of abstract members.
So whenever we have the requirements such as it requires through the application at many
places, then we create an interface with that method so that we can implement it at our own way
according to the requirements.
e.g.

Interface Inf
{
void Print();
}

Class ExcelClass:Inf
{
public override void Print()
{
//Write code to print in excel
}
}

Class WordPrintClass: Inf
{
public override void Print()
{
//Write code to print in Word
}

}
Class PDFPrintClass: Inf
{
public override void Print()
{
//Write code to print in PDF
}
}


Also to implement the multiple inheritances, we use inheritance.

7) In which situation inheritance is used in your project?

When we want to have some common features for multiple classes then we go for inheritance.
To inherit the properties of base class to their derived class.

8) In which situation abstract class is used in your project?
Abstract class is same as abstract. So go to the Q 2 for the details.




Scenario Based Questions in Microsoft Technologies - .Net with Answers


Hai Friends,
As we know that getting more experience and then going for the interview requires
more knowledge and if we see, it requires more practical knowledge.
So in the continuation, I am trying to post few questions of OOPS which are
scenario based and will be helpful when you are going for the interviews with 3+
years experience. These questions will definitely make you to think something more
which you were thinking before about the answer of a particular question. With the
hope that these questions and answers will be helpful to you, I am posting them
and will try to update and include more in the future.
These questions are scenario based questions in .Net technologies which will help to
prepare for the interviews. Few questions are related to OOPs concepts, and then
few on Garbage Collector and memory related. So you can prepare them
accordingly. These questions will be useful for those who are having the 3+ years
experience and looking out for the opportunities in good companies.
1. How the Encapsulation is different from Abstraction? I think both are used to
hide the unnecessary details? Then how they are different?
Ans.
Yes, Both Encapsulation and Abstraction do the same thing but with few differences.
Encapsulation mainly encapsulates the object and so hides the details as well as it
binds the data.
So Encapsulation = Hiding + Binding the data
How it hides the data? Real-time Example?
Take the example of n-Tier application where we have an additional layer called
Business Objects. This layer
contains all the entities with their properties. Take an entity name: Employee. This
Employee will have the
class name "EmployeeBO.cs" and contains the public properties like EmpId, EmpName, Sal ets
EmployeeBO.cs

So this is the presentation of one property in the Business object class. Now wherever
we want this attribute,
We just need to create the object of this class and set/get the value of EmpId as:
// set the EmpId
EmployeeBo objEmployeeBO = new EmployeeBO();
objEmployeeBO.EmpId = 101;

// get the EmpId
int empId = objEmployeeBO.EmpID;
Now the question is where its setting or getting the value?
EmpId is the public property in the EmployeeBO class and contain no value. Only
_empId contains the value
which is private and so it is not accessible.
So binding of the data happens to the EmpId through _empID and hiding happends
through _empId which is
private. The Data is accessed through the Public property while the actual data is in
private variable. So
binding + hiding using Encapsulation.
Abstraction is to ignore the unnecessary details and get the required
details. So it also hides the unnecessary details. How?
Abstract class is the special type of class which can contain the abstract and
concrete members. If we define
The member (Method/Property) as abstract, it must be overrides to the child class.
We are not bothering here About the non-abstract or concrete members. Which is
an unnecessary detail? If we ad an additional concrete Member in the abstract
class, we need not to do anything in the child class. But if we add
the abstract members, we must have to override it. So abstract doesn't care about
the concrete members which are unnecessary for it and so it hides those details.

2. What do you mean by early binding and late binding in the object bindings?
Which is good? Please give me a scenario where you have used the early binding
and late binding concepts in your application?
Ans.In .Net, the early binding and last binding concepts comes under the
polymorphism. As we know that there are 2 types of polymorphism-
1. Compile Time polymorphism
2. Run time polymorphism
The Compile Time polymorphism also called as the Overloading where we have
the same method name with different behaviors. By implementing the multiple
prototype of the same method, we can achieve the behavior of the Overloading.
Also this behavior is valid only for a single class. It means we should have all the
overloaded methods in the same class.
e.g.

The Run time polymorphism also named as the Overriding. This concept works in
between classes or multiple classes or parent child classes where the child class has
to get the behavior of the base class by inheriting the base class.
In this concept we generally have an abstract or virtual method in the base class
and we override that method in the child class by using the override method.
e.g.

So now we know the Compile Time polymorphism and Run Time polymorphism. The
compile time polymorphism uses the concept of early binding and Run time
polymorphism uses it as the late binding.
In early binding, the runtime (CLR) gets the behavior in the compilation of the
program. It means that the method behavior will get compiled before in the early
binding.
In Late binding, like Overriding, the behavior of the class and methods gets by the
CLR when creating the object means at runtime. So, in the late binding the
behavior of the class members identified by the CLR at runtime.
Now come to the next part of the question-which is good?
One cant say about the answer of this question, there are the scenarios where the
early binding is good. When you have lot of objects and in that case, the early
binding behavior performs well. While the late binding will be good when we have
less objects. Lets say you want the dropdown list to be loaded when you click on it
and not while the loading of the page. So in some scenario, it will be good if we
have while load and it will not be good when you click.
So its all depends on how you have implemented and the form structure.

3. In garbage collection, how the object generations come in the picture? How many
generations an object can have? Please tell me the process of disposing the objects
based on the generations? Can an object move from one generation to another? If
yes then why? Whats the need to have different generations as we are going to
dispose the objects which are marked by the Garbage collector?
Ans.
Lets start with what is Garbage collection first and then we will come to our
main question of the post. As we know that all the objects created using the new
operator gets fits in to the Heap memory. So whenever a new object gets created,
it tries to fit in the heap memory. Now lets say the heap memory is full and there
is no place to keep another newly created object.
In that case the Garbage collector installed, which is the background process, runs
through CLR and take the unused objects memory. It mainly cleanup the heap
memory and the new objects get placed in to it.
Now the question comes that for which objects it reclaims for the memory?
How the object generations come in the picture?
It depends on the objects generations. The CLR finds out the objects which are no
longer used by the application since longer time and then the Garbage collection
reclaim their memory.
How many generations an object can have? Please tell me the process of
disposing the objects based on the generations?
Actually there are 3 generations exists for the objects which are written under the
.Net framework library. When a new object gets created, by default it moves to the
generation 0.
Can an object move from one generation to another?
Now when the generation 0 objects gets occupied with the memory and garbage
collector gets called by the run-time. It checks the objects which are no longer used
by the application and mark them for deletion. After deleting or reclaim the
memory, the older objects moved to next generation i.e. Generation 1. Now the
next time the CLR will check for the Generation 1 object too and if it finds that in
generation 1 if the objects are not used since longer time, it will mark them for
release and move the remaining objects to generation 2.
In generation the objects which are under the main method, exists as they gets
removed either at the end of the program or when both the generation 0 and
generation 1 objects are using.
Whats the need to have different generations as we are going to dispose
the objects which are marked by the Garbage collector?
With the different generation, it improves the performance of the application as the
Garbage collector need not to check for each of the objects in the memory. It first
checks for the generation 0 objects and reclaim the memory. If still needs then
goes to the generation 1 and then 2.

4. What is object graph in garbage collector? Is this the graph physically exists? Or
how this graph gets created?
Ans. When the Garbage Collector gets called by the CLR to DE-allocate the memory
in the heap, the Garbage Collector start finding the references of all the reachable
objects which are currently in use. So it find the objects which are used by the
processes and for rest of objects which are un-reachable or the Garbage collector is
not able to find the references for them, it marks them for deletion.
Here the Garbage collector makes an Object graph which keeps track of all the
objects which are marked for deletion. After the deleting the references for those
objects, the heap memory gets compacted and a new root becomes available to use
by the new created object.
Is this the graph physically exists? Or how this graph gets created?
No, this object graph creates virtually by the Garbage Collector to keep all the
objects and to make them for deletion. This is the Garbage Collector responsibility
to create this object graph and gets the references of each reachable object which
are used by the application

5. Can we suppress the Garbage collector? If yes, then why do we need to suppress
it as it is used to reclaim the unused memory and which improve s the performance
of our application?
Ans. Yes, We can suppress the Garbage Collector. There is the Static method in GC
class called as SupressFinalize.
GC.SuppressFinalize(objectName);
This Static method takes a parameter for the object. So we can pass it to
suppress the claiming memory for this object.
Now the question comes "why do we need to suppress it as it is used to reclaim
the unused memory",
So, whenever we are using dispose method for class object,which is capable of
disposing the object and in that case we don't need to use this method to again
reclaim the memory.
e.g.
public class DemoClass : IDisposable

{
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
As we have seen above,the DemoClass is inherited by IDisposable interface and
which have the Dispose method to implement.
Hence after implementation of Dispose() method, we need not to reclaim the
memory using the Garbage collector and so we can use the SuppressFinalize() for
the current class object.

6. We already have the Finalize method which reclaims the memory using the
Garbage collector. This is automatic process then why do we have the Dispose ()
method? Is this method different from Finalize ()? What is the interface from which
the Dispose () method inherited?
Ans. Yes, We have the Finalize() method which is used to reclaim the memory for
the unused objects. The Finalize() method is sufficient to release the memory from
heap for the un-referenced object but it is only for the managed objects. So
Finalize() method can reclaim the managed objects memory from the heap which
are not used since longer time.
Then what about the objects which are unmanaged? The objects which are out of
.Net CLR? The objects where the CLR can't be used to manage? Dispose() method
is used for all those objects which do not comes under CLR or under the Managed
heap. Dispose() method can be overrides and can be written to reclaim the object
of those classes. Dispose() method is implemented by using the IDisposable
interface.
e.g.public class TestClass : IDisposable
{
public void Dispose()
{
Dispose(true);
}

}
7. Can we call the Finalize() method to be executed explicitly when we want that
particular object memory to be reclaim by the Garbage Collector? If yes, then
where do we need to write the code? If no then why?
Ans. No, the Finalize() method can't be called as Explicitly. The Garbage collector
calls it when the Heap memory is having no space to allocate the new object in the
heap.
Finalize() method is mainly used to perform the cleanup on the unmanaged
resources which are held by the current object.
Working Finalization: Until the Finalize method is overrides, the Garbage
collection doesn't mark the object to claim its memory.Internally the Finalization
Queue keep each of the objects which are marked for deletion by GC and then the
Finalize() method gets called.
The Object must be inaccessible(no reference found) to put or keep in the
Finalization Queue.
Limitations: There are the limitation for Finalization:
a. Un-Deterministic - it is hard to find that when the Finalize() method will be
called.
b. There is no guarantee that which object will be disposed first.
The C# compiler doesn't allow the overriding of Finalize() method an due to that
we need to write the Destructor of the class.
As the GC is non-Deterministic so we can implement the Dispose()
method explicitly to claim the unused memory by the Garbage collection.
For More details on GC, check the link:
GC Internal

8. Can we inherit child class from 2 base classes? If yes then how? If not then why?
What is this scenario called as in OOPs? How to implement this kind of scenario
where we need to inherit the methods from more than one base class?
Ans. No, We can't inherit more than one base class in to child class. This leads to
the Multiple Inheritance where the child class can inherit more than one base class
and the Multiple Inheritance doesn't support in .Net.
So this scenario is called as Multiple inheritance(a type of inheritance in OOPs).
If you do so, you will see the error 'Interface name expected.' as below:



To implement these kind of scenarios, we need the help of Interfaces, Where we
can convert the second base class to Interface and then we can inherit one base
class and second Interface.



9. How the Virtual methods are different from General methods? Can we have a
method in the base class and then in the child class can we write the same method?
If not? Why? What is the error we will get if we write the same method in the child
class with the same name as the parent class method name?
Ans. Yes, Virtual methods are different from the general method. The
Virtual methods are the special type of methods which can be overrides in
the child class and then the child class method will be the output or the
default result.


And when creating the child class object, it will take the child class
method as the preference as below:


Now, if we have the same method in the child class as base class then it will
hide the base class method by default and what ever is implemented in the child
class will get executed.


So here we can see that the error will not come but it will show the warning to
use the 'new' operator instead to hide the base class method. This scenario is
called as Shadowing in the OOPs.

10. Why do we need abstract class or abstract members? Cant we simply write the
general methods and fulfill our requirements? Can we get any advantage by
implantation of abstract members? As per the abstract class scenario, lets say we
have an abstract method called Show () in the abstract base class. Now if I am
inheriting this base class to a child class, we need to override this abstract method
to the child class. And then we will call this method by creating instance of child
class.Now if we only have the method in the child class and then create the
instance and call the same method? Then why abstract class method? Is that
method doing anything here?
Ans. Abstract class or abstract members(methods, properties) are those
which are not complete. So when the class contains at-least one
abstract member,the class must be defined with abstract class.
We can also say that 'When the class does not provides the
full functionality, we can declare the class as abstract'.
the abstract class works based on the child class memory. Due to that
we cant create the object of Abstract class, instead we can create
the reference of the abstract class.


11. How abstract class and interfaces are different? Cant we create an abstract class
by having all the members as abstract members and wherever required inherit and
implement its members? Then why interface? I think interface is also doing the
same thing? Then how they are different?

12. Can we have abstract properties in Interface? If yes, then how to write the syntax
for the abstract property which is having the return type string?

13. Can we write static methods inside a non-static class? Is it possible to call a non-
static method inside the static method? If yes then how?

14. Shadowing is the special type of overriding? How? Please explain?

15. When we inherit a class which is having the private members. Are the private
members also gets inherited? If yes? Why cant we get them by the class object? If
no then why?

16. What is the Difference between Coupling and Cohesion? If the components are
more cohesive the software is good? Or vice versa?



17. See the below code snippet and think about the output.




18. What is the Difference between HTTP enabled WCF Service and Web Services? I
think if we restrict the WCF service just for the HTTP communication, both WCF and
Web Service will have the same behavior. Then why still people prefer to have the
WCF service rather than the Web Service. What all the things which can be
achieved through HTTP enabled WCF service and cant be just from Web Service.

19. What is the Difference between SOAP enabled Services and ReST
Services? Which one is preferred and why?

Das könnte Ihnen auch gefallen