Pages

Thursday, March 31, 2011

Dot NET Interview

Differences between Process and Thread:
A process is a collection of virtual memory space, code, data, and system resources.
A thread is code that is to be serially executed within a process.
A processor executes threads, not processes, so each application has at least one process,
and a process always has at least one thread of execution, known as the primary thread.
A process can have multiple threads in addition to the primary thread.
Prior to the introduction of multiple threads of execution,
applications were all designed to run on a single thread of execution.When a thread begins to execute, it continues until it is killed or until it is
interrupted by a thread with higher priority (by a user action or the kernel’s thread scheduler).
Each thread can run separate sections of code, or multiple threads can execute the same section of code.
Threads executing the same block of code maintain separate stacks.
Each thread in a process shares that process’s global variables and resources.
The major difference between threads and processes is
1.Threads share the address space of the process that
created it; processes have their own address.2.Threads have direct access to the data segment of its
process; processes have their own copy of the data segment
of the parent process.3.Threads can directly communicate with other threads of
its process; processes must use interprocess communication
to communicate with sibling processes.4.Threads have almost no overhead; processes have
considerable overhead.

5.New threads are easily created; new processes require
duplication of the parent process.

6.Threads can exercise considerable control over threads of
the same process; processes can only exercise control over
child processes.

7.Changes to the main thread (cancellation, priority
change, etc.) may affect the behavior of the other threads
of the process; changes to the parent process does not
affect child processes.

————————————————————————————-

Difference between read only and constant
variables:

Readonly variable can be assigned at declaration or at run
time which is must be in constructor. Readonly value can’t
be modified.

Constant variable must be assigned at the time of
declaration only ,which is can’t be modified.

Difference between user controls and custom controls

User control

1) Reusability web page
2) We can’t add to toolbox
3) Just drag and drop from solution explorer to page (aspx)
4) U can register user control to. Aspx page by Register tag
5) A separate copy of the control is required in each application
6) Good for static layout
7) Easier to create
8)Not complied into DLL
9) Here page (user page) can be converted as control then
We can use as control in aspx

Custom controls

1) Reusability of control (or extend functionalities of existing control)
2) We can add toolbox
3) Just drag and drop from toolbox
4) U can register user control to. Aspx page by Register tag
5) A single copy of the control is required in each application
6) Good for dynamics layout
7) Hard to create
Compiled in to dll

——————————————————————————-

Difference between TypeOf and GetType

TypeOf and GetType Produce the same information but the
difference is where they get theis information from;
typeOf is used to get the type based on a class, that means
if you use typeOf with object, it will gives you error. you
must pass class as parameter. Whereas GetType is used to
get the type based on as object (an instance of a class)
means GetType needs parameter of object rather than class name

————————————————————————————

Difference between “as” and “is” keyword

as operator use for casting
where is operator is use for comparision.

———————————————————————————

ASP.NET Page Life Cycle:


Each request for an .aspx page that hits IIS is handed over to HTTP Pipeline. HTTP Pipeline is a chain of managed objects that sequentially process the request and convert it to plain HTML text content. The start point of HTTP Pipeline is the HttpRuntime class. The ASP.NET infrastructure creates each instance of this class per AppDomain hosted within the worker process. HttpRuntime class picks up an HttpApplication object from an internal pool and sets it to work on the request. It finds out what class has to handle the request. The association between the resources and handlers are stored in the configurable file of the application. In web.config and also in machine.config you will find these lines in section.


If you run through the following program, it will be much easier to follow:



This extension can be associated with HandlerClass or HandlerFactory class. HttpApplication object gets the page object that implements the IHttpHandler Interface. The process of generating the output to the browser is started when the object calls ProcessRequest method.Page Life Cycle

Once the HTTP page handler class is fully identified, the ASP.NET runtime calls the handler’s ProcessRequest to start the process. This implementation begins by calling the method FrameworkInitialize(), which builds the control trees for the page. This is a protected and virtual member of TemplateControl class, class from which page itself derives.

Next the processRequest() makes page transits various phases: initialization, loading of viewstate and postback data, loading of page’s user code and execution postback server-side events. Then page enters in render mode, the viewstate is updated and HTML generated is sent to the output console. Finally page is unloaded and request is considered completely served.

Stages and corresponding events in the life cycle of the ASP.NET page cycle:

Stage Events/Method
Page Initialization Page_Init
View State Loading LoadViewState
Postback data processing LoadPostData
Page Loading Page_Load
PostBack Change Notification RaisePostDataChangedEvent
PostBack Event Handling RaisePostBackEvent
Page Pre Rendering Phase Page_PreRender
View State Saving SaveViewState
Page Rendering Page_Render
Page Unloading Page_UnLoad


Some of the events listed above are not visible at the page level. It will be visible if you happen to write server controls and write a class that is derived from page.

Page Execution Stages

The first stage in the page life cycle is initialization. This is fired after the page’s control tree has been successfully created. All the controls that are statically declared in the .aspx file will be initialized with the default values. Controls can use this event to initialize some of the settings that can be used throughout the lifetime of the incoming web request. Viewstate information will not be available at this stage.

After initialization, page framework loads the view state for the page. Viewstate is a collection of name/value pairs, where control’s and page itself store information that is persistent among web requests. It contains the state of the controls the last time the page was processed on the server. By overriding LoadViewState() method, component developer can understand how viewstate is restored.

Once viewstate is restored, control will be updated with the client side changes. It loads the posted data values. The PostBackData event gives control a chance to update their state that reflects the state of the HTML element on the client.

At the end of the posted data changes event, controls will be reflected with changes done on the client. At this point, load event is fired.

Key event in the life cycle is when the server-side code associated with an event triggered on the client. When the user clicks on the button, the page posts back. Page framework calls the RaisePostBackEvent. This event looks up for the event handler and run the associated delegate.

After PostBack event, page prepares for rendering. PreRender event is called. This is the place where user can do the update operations before the viewstate is stored and output is rendered. Next stage is saving view state, all the values of the controls will be saved to their own viewstate collection. The resultant viewstate is serialized, hashed, base24 encoded and associated with the _viewstate hidden field.

Next the render method is called. This method takes the HtmlWriter object and uses it to accumulate all HTML text to be generated for the control. For each control the page calls the render method and caches the HTML output. The rendering mechanism for the control can be altered by overriding this render method.

The final stage of the life cycle is unload event. This is called just before the page object is dismissed. In this event, you can release critical resources you have such as database connections, files, graphical objects etc. After this event browser receives the HTTP response packet and displays the page.

—————————————————

Types of polymerphism and explain about dynamic polymerphism?

Types of polymorphism are:
1. Run Time polymorphism
2. Compile Time Polymorphism

Dynamic polymorphism means binding the data during run
time. It is also called late binding. Example for dynamic
polymorphism is virtual functions

———————————————————-

How do you restrict the type which can be used in custom generic?

To restrict a type in Generic just specify the constraint
immediately following the method header, prior to the curly
braces of the method block:

For EX: you can restrict a type parameter to implement
IComparable

public class ConsoleTreeControl
{
// Generic method Show
public static void Show(BinaryTree tree, int indent)
where T : IComparable
{
//Your Code

}
}

So this cannot implement IComparable interface.

—————————————————————————–

i want display a given number into Rupees Format Like Given number is : 156735 my Expected output is 1,56,735. how to display?

You Can Use Just
String.Format(“{0:C}”,156735);
-----------------------------------------------------------
Why do we need interfaces?
Reason1: In C# Multiple inheritence concept will be
implemented by Interfaces.
Reason2: When multiple ppl are working on one sigle
project, if they need to use some common functionality (for
example initializing the variables for thier modules)
instead of writing their own function name (like init,
initialize, setup etc etc) if we can write one single
function name (lets say initialize) then this function can
be implemented by any user who derives. That’s it.
public interface IInitialize
{
void InitializeVar();
}
public classs Box:IInitialize
{
void InitializeVar()
{
//initializion of variables goes here
}
public classs Rectangle:IInitialize
{
void InitializeVar()
{
//initializion of variables goes here
}
------------------------------------------
Wats the diff between sealed class and private class in inheritance
In private Class: We can create a constructor and therefore
we can create an instance of that class.
But
In Sealed class we can not create a constructor of that
class, so no instance of that class is possible.

Private Constructor of a Private Class = Sealed Class.
———————————————————–

What is the difference between Web Server and Application server?

(1) Webserver serves pages for viewing in web browser, application server provides exposes businness logic for client applications through various protocols

(2) Webserver exclusively handles http requests.application server serves bussiness logic to application programs through any number of protocols.

(3) Webserver delegation model is fairly simple,when the request comes into the webserver,it simply passes the request to the program best able to handle it(Server side program). It may not support transactions and database connection pooling.

(4) Application server is more capable of dynamic behaviour than webserver. We can also configure application server to work as a webserver.Simply applic! ation server is a superset of webserver.

———————————————————————————————

What is use of super class

Super class is also called as the base class or as the
parent class.

we can inherit methods of base class to our derived class
by using inheritance, where derived class is also callled
as the child class if and only if it is derived from the
parent

Exmaple you are the derived class of your parents who are
the base class for you, few of their methods
(looks,emotions,way of speech etc) are into you but few of
our methods(style,behaviour etc) cannot be into your parents

No comments:

Post a Comment