I, Me, Myself

My photo
Hyderabad, Hindhu/AndhraPradesh, India
CoOl,jOvial,strAight fOrward

Search

Thursday, May 20, 2010

DotNet Interview Questions


DOTNET QUESTIONS AND ANSWERS
1.       What is .Net Framework?
The .NET Framework is an integral Windows component that supports building and running the next generation of applications and XML Web services. The .NET Framework is designed to fulfill the following objectives
The .NET Framework has two main components: the common language runtime and the .NET Framework class library. The common language runtime is the foundation of the .NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code. The class library, the other main component of the .NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services

2.       ASP.Net life Cycle?
The Life Cycle of a page when requested for the first time:
Initializing: During this phase, the server creates an instance of the server control
Loading: During this phase, the instance of the control is loaded onto the page object in which it is defined.
PreRendering: During this phase, the control is updated with the changes made to it. This prepares the control for rendering.
Saving: During this phase, the state information of the control is saved. For example, if a value is set for the control during the Load event, it is embedded in the HTML tag that will be returned to the browser.
Rendering: During this phase, the server creates the corresponding HTML tag for the control.
Disposing: During this phase, all cleanup tasks, such as closing files and database connections opened by the control are performed.
Unloading: During this phase, all cleanup tasks, such as destroying the instances of server control are performed. This is the final event in the life cycle of a server control

3.       Assembly’s
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.
Assemblies are a fundamental part of programming with the .NET Framework. An assembly performs the following functions:
·         It contains code that the common language runtime executes. Microsoft intermediate language (MSIL) code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest. Note that each assembly can have only one entry point (that is, DllMain, WinMain, or Main).
It forms a reference scope boundary. The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests. It specifies the types and resources that are exposed outside the assembly. The manifest also enumerates other assemblies on which it depends.
Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.
There are several ways to create assemblies. You can use development tools, such as Visual Studio 2005, that you have used in the past to create .dll or .exe files. You can use tools provided in the Windows Software Development Kit (SDK) to create assemblies with modules created in other development environments. You can also use common language runtime APIs, such as to Refelection.emit  create dynamic assemblies.
GAC & installation Files
Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.
You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.
Ex : gacutil [options] [assemblyName | assemblyPath | assemblyListFile]

4.       MSIL
When compiling to managed code, the compiler translates your source code intoMicrosoft intermediate language (MSIL),which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.
5.       Compilers
6.       JIT
7.       Runtime Compilers and debug compilers
8.       Web.config & Machine .config
9.       Authentication a & authorization
10.   Events ,event bubbling
11.   String and string builder
12.   WCF and WCF overloading
13.   Linq to Sql
14.   SharePoint server overview
15.   WSS and Moss
16.   Sqlconnection flow
17.   Cursors,triggers,indexes

Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time. For example, you can use cursor to include a list of all user databases and make multiple operations against each database by passing each database name as a variable
SQL Server is very good at handling sets of data. For example, you can use a single UPDATE statement to update many rows of data. There are times when you want to loop through a series of rows a perform processing for each row. In this case you can use a cursor.



Creates a DML, DDL, or logon trigger. A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view.

18.   CCW & RCW
19.   Delegate
A delegate can hold reference/s to one more more functions and invoke them as and when needed.
A delegate needs the method's name and its parameters (input and output variables) when we create a delegate. But delegate is not a standalone construction. it's a class. Any delegate is inherited from base delegate class of .NET class library when it is declared. This can be from either of the two classes
from System.Delegate or System.MulticastDelegate.
If the delegate contains a return type of void, then it is automatically aliased to the type of System.MulticastDelegate. This can support multiple functions with a += operator. If the delegate contains a non-void return type then it is aliased to System.Delegate class and it cannot support multiple methods.

20.   Reversing string in C#

using System;
 
static class StringHelper
{
    /// 
    /// Receives string and returns the string with its letters reversed.
    /// 
    public static string ReverseString(string s)
    {
        char[] arr = s.ToCharArray();
        Array.Reverse(arr);
        return new string(arr);
    }
}
21.   Magic Tables
There are 2 Magic Tables in SQL server Inserted and Deleted.
These are mantained by SQL server for Internal processing whenever an update, insert of delete occur on a table. However, we can refere these tables in a Trigger.
Whenever an update table statement is fired SQL server mantains the original row before updation in a deleted table and New (updated )row in a Inserted Table.

Same is the case when an insert is fired Only Inserted table is populated with inserted Row.
and when Delete table statement is fired Deleted table is populated with the deleted row.
1. Inserted
     Insert
     Update
2. Deleted

22. Views
23.   State management
A new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, this would typically mean that all information associated with the page and the controls on the page would be lost with each round trip. For example, if a user enters information into a text box, that information would be lost in the round trip from the browser or client device to the server.
To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:
·         View state
·         Control state
·         Hidden fields
·         Cookies
·         Query strings
·         Application state
·         Session state
·         Profile Properties
View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways. However, application state, session state, and profile properties all store data in memory on the server. Each option has distinct advantages and disadvantages, depending on the scenario.
View State
The view state  property provides a dictionary object for retaining values between multiple requests for the same page. This is the default method that the page uses to preserve page and control property values between round trips.
When the page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field, or multiple hidden fields if the amount of data stored in the view state property exceeds the specified value in the Max pagestate field length property. When the page is posted back to the server, the page parses the view-state string at page initialization and restores property information in the page.
ViewState["color"] = "red";
b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state. 



c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed. 



d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site. 



e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL. 



2. Server – Side State Management 

a. Application State - Application State information is available to all pages, regardless of which user requests a page. 



b. Session State – Session State information is available to all pages opened by a user during a single visit. 



Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties. 

24.   How to call JavaScript function in code behind?
 Clientmanager.registerstartupscript();
25.    Static class and static methods
A static constructor is only called one time, and a static class remains in memory for the lifetime of the application domain in which your program resides. 


What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
Example of Compile Time Polymorphism: Method Overloading
Example of Run Time Polymorphism: Method Overriding

Example of Compile Time Polymorphism

Method Overloading
- Method with same name but with different arguments is called method overloading.
- Method Overloading forms compile-time polymorphism.
- Example of Method Overloading:
class A1
{
void hello()
{ Console.WriteLine(“Hello”); }

void hello(string s)
{ Console.WriteLine(“Hello {0}”,s); }
}


Example of Run Time Polymorphism

Method Overriding
- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.
- Method overriding forms Run-time polymorphism.
- Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. While by default in Java each function are virtual.
- Example of Method Overriding:
Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent
{
override void hello()
{ Console.WriteLine(“Hello from Child”); }
}

static void main()
{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.



Value type and reference type
Get and Post Method
Get Vs Post Method

Get Vs Post Method to send data to the server

Get and Post are methods used to send data to the server:
With the Get method, the browser appends the data onto
the URL. With the Post method, the data is sent
as "standard input."

Use GET:
- during development for debugging purposes (although in ASP.NET it's
   also easy to see what has been sent through POST).
- if you want your visitors to be able to bookmark the submitted pages
- if you want to refer to submitted pages using hyperlinks

Use POST:
- for forms with password fields
- for large forms or forms with large text fields

Please note that web forms in ASP.NET use POST by default.

It can be changed into GET, but only for small forms. Web forms can post a lot
of data, especially when ViewState is involved.
Access modifiers
Classes
and structs can be restricted so that only the program or namespace they are declared in may use them. Class members can be restricted so that only derived classes can use them, or restricted so that only classes within the current namespace or program can use them. Access modifiers are keywords added to the class, struct, or member declaration to specify these restrictions. So in a nutshell access modifiers are keywords which control the visibility of class members and other code constructs.

The access modifiers in .NET are
1. public

2. private

3. protected

4. internal

5. protected internal
public

Public means visible to everyone and everywhere.

Access cases
1. By objects of the class

2. By derived classes
private

Private means hidden and usable only by the class itself. No code using a class instance can access a private member and neither can a derived class. Information or functionality that will not be needed or has no meaning outside of the context of a specific class should be made private.

Access cases
1. Cannot be accessed by object

2. Cannot be accessed by derived classes
protected

Protected members are similar to private ones in that they are accessible only by the containing class. However, protected members also may be used by a descendant class. So members that are likely to be needed by a descendant class should be marked protected.

Access cases
1. Cannot be accessed by object

2. By derived classes
internal

Internal are public to the entire assembly but private to any outside assemblies. Internal is useful when you don't want to allow other assemblies to have the functionality.

Access cases

In same assembly (public).
1. By objects of the class

2. By derived classes
In other assembly (internal)
1. Cannot be accessed by object

2. Cannot be accessed by derived classes
protected internal

Finally, we have the only compound access modifier allowed in .NET. Members marked as protected internal may be accessed only by a descendant class that's contained in the same assembly as its base class. You use protected internal in situations where you want to deny access to parts of a class' functionality to any descendant classes found in other
applications.

Note: that it's illegal to combine two access modifiers for a class but can only be applied to the members.

Access cases

In same assembly (protected).
1. Cannot be accessed by object

2. Can be accessed by a derived classes
In other assembly (internal)
1. Cannot be accessed by object

2. Cannot be accessed by derived classes


SqlServer Reporting Services (SSRS)
SSRS 2005 is the latest version of SQL Reporting Services, and ships with all versions of SQL Server 2005. SSRS allows you to quickly and easily create reports from multiple database sources. The finished reports can be presented directly from the reporting services website, or they can be displayed in your web- or Windows-based applications. Reports can be exported to multiple formats, including comma delimited text, XML, portable document format (pdf) and Microsoft Excel.
Crystal Reports:


Formula Fields
Parameter Fields
GroupName Fields
Running Total Fields
Special Fields
Unbound Fields

What is Global. asax
Global.asax is a file used to declare application-level events and objects. Global.asax is the ASP.NET extension of the ASP Global.asa file. Code to handle application events (such as the start and end of an application) reside in Global.asax. Such event code cannot reside in the ASP.NET page or web service code itself, since during the start or end of the application, its code has not yet been loaded (or unloaded). Global.asax is also used to declare data that is available across different application requests or across different browser sessions. This process is known as application and session state management.

The Global.asax file must reside in the IIS virtual root. Remember that a virtual root can be thought of as the container of a web application. Events and state specified in the global file are then applied to all resources housed within the web application. If, for example, Global.asax defines a state application variable, all .aspx files within the virtual root will be able to access the variable.

Like an ASP.NET page, the Global.asax file is compiled upon the arrival of the first request for any resource in the application. The similarity continues when changes are made to the Global.asax file: ASP.NET automatically notices the changes, recompiles the file, and directs all new requests to the newest compilation.
Validation Controls
RequiredFieldValidator
RangeValidator
RegularExpression validator
ComapareValidator
Custom Validator
validation Summary
Differences Between Varchar and Nvarchar
Varchar means Variable-length Character string.
Nvarchar will store Unicode characters.Both will be used all most for the same purpose but with little difference.
Varchar will store the 8-bit data in database where as Nvarchar will be stored as 16-bit data in Database.
In Sql server 2005
nvarchar stores unicode data while varchar stores ascii data. They function identically but nvarchar takes up twice as much space.
An nvarchar column can store any Unicode data. A varchar column is restricted to an 8-bit codepage. Some people think that varchar should be used because it takes up less space. I believe this is not the correct answer. Codepage incompatabilities are a pain, and Unicode is the cure for codepage problems. With cheap disk and memory nowadays, there is really no reason to waste time mucking around with code pages anymore.
All modern operating systems and development platforms use Unicode internally. By using nvarchar rather than varchar, you can avoid doing encoding conversions every time you read from or write to the database. Conversions take time, and are prone to errors. And recovery from conversion errors is a non-trivial problem.
If you are interfacing with an application that uses only ASCII, I would still recommend using Unicode in the database. The OS and database collation algorithms will work better with Unicode. Unicode avoids conversion problems when interfacing with other systems. And you will be preparing for the future. And you can always validate that your data is restricted to 7-bit ASCII for whatever legacy system you're having to maintain, even while enjoying some of the benifits of full Unicode storage.
nvarchar stores data as unicode, so, if you're going to store multilingual data (more than one language) in a data column you need the N variant.

No comments:

Followers