Thursday, December 31, 2009

Generics and other microsoft .net interview question

Introduction

The support for something like 'Templates' found in the good old(?) C++. The support for the concept of type parameters, which makes it possible to design classes which take in a generic type and determine the actual type later on.

This means that by using a generic type parameter T, you can write a single class MyList and the client code can use it as MyList, MyList or MyList without any risk of runtime casts or boxing operations.

Version 2.0 of the .NET Framework introduces a new namespace viz. System.Collections.Generic, which contains the classes that support this concept, like the List, Queue, Stack, LinkedList and many more which you can use effectively in your programs.

Advantages of Generics
In the earlier versions, before .NET 2.0, generalization was accomplished by casting types to and from the universal base type System.Object. Generics provide a solution to this limitation in the common language runtime and the C# language. This limitation can be demonstrated with the help of the ArrayList collection class from the .NET Framework base class library. ArrayList is a highly convenient collection class that can be used without any modifications to store any reference or value type.
// The .NET Framework 1.1 way of creating a list
ArrayList list1 = new ArrayList();
list1.Add(3);
list1.Add(105);
//...
ArrayList list2 = new ArrayList();
list2.Add("First item.");
list2.Add("Second item");
//...


But this convenience comes at a cost. Any reference or value type that is added to an ArrayList is implicitly typecast to System.Object. If the items are value types, they must be boxed when added to the list, and unboxed when they are retrieved. The casting, boxing and unboxing operations degrade performance; the effect of boxing and unboxing can be quite significant in scenarios where you must iterate through large collections.
So, what we need is, flexibility of the ArrayList but it should be more efficient and should provide some ways of type checking by the compiler, without sacrificing on the reusability of that class with different data types. An ArrayList with a type parameter? That is precisely what generics provide. Generics would eliminate the need for all items to be type cast to Object and would also enable the compiler to do some type checking.
In the generic List collection, in System.Collections.Generic namespace, the same operation of adding items to the collection looks like this:
// The .NET Framework 2.0 way of creating a list
List list1 = new List();
list1.Add(3); // No boxing, no casting
list1.Add("First item"); // Compile-time error

For the client code, the only added syntax with List compared to ArrayList is the type argument in the declaration and in instantiation. In return for this slightly greater coding complexity, you can create a list that is not only safer than ArrayList, but also significantly faster, especially when the list items are value types.

Generic Classes
Generic classes encapsulate operations that are not specific to any particular data type. The most common use for generic classes is with the collections like linked lists, hash tables, stacks, queues, trees and so on where operations such as adding and removing items from the collection are performed in more or less the same way regardless of the type of the data being stored.
public class Node
{
T head;
T next;
}
Here, T is the type parameter. We can pass any data type as parameter.
This class can be instantiated like this:
Node node = new Node();
This will tell the compiler that the properties, head and next are of type string. Instead of string, you can substitute this with any data type.

Generic Methods
A generic method is a method that is declared with a type parameter.
void Swap( ref T left, ref T right)
{
T temp;
temp = left;
left = right;
right = temp;
}

The following code example shows how to call the above method:
int a = 1;
int b = 2;
Swap (a, b);
You can also omit the type parameter because the compiler will automatically identify it for you. The following is also a valid call to the same method:
Swap (a, b);


Write your own Generic class
The following example demonstrates how you can write your own generic classes.
The example shown below is a simple generic linked list class for demonstration purpose:
using System;
using System.Collections.Generic;
public class MyList //type parameter T in angle brackets
{
private Node head;

// The nested class is also generic on T.
private class Node
{
private Node next;
//T as private member data type:
private T data;
//T used in non-generic constructor:

public Node(T t)
{
next = null;
data = t;
}


public Node Next
{
get { return next; }
set { next = value; }
}

//T as return type of property:
public T Data
{
get { return data; }
set { data = value; }
}
}

public MyList()
{
head = null;
}

//T as method parameter type:
public void AddHead(T t)
{
Node n = new Node(t);
n.Next = head;
head = n;
}

public IEnumerator GetEnumerator()
{
Node current = head;
while (current != null)
{
yield return current.Data;
current = current.Next;
}
}

}
Notice the declaration of the above class :
public class MyList
T is the parameter type. Throughout the above code, the data type for the Node is T rather than any specific types like int or string or any other class. This gives flexibility to the programmer to use this class with any data type he wishes to use.
The following code example shows how the client code uses the generic MyList class to create a list of integers. Simply by changing the type argument, the code below can be easily modified to create lists of strings or any other custom type:

class Program
{
static void Main(string[] args)
{
//int is the type argument.
MyList list = new MyList();

for (int x = 0; x < 10; x++)
list.AddHead(x);
 foreach (int i in list)
Console.WriteLine(i);
Console.WriteLine("Done");
 }
}

How generics are handled by the .NET runtime
When a generic type or method is compiled into MSIL, it contains metadata that identifies it as having type parameters. How this MSIL which contains generic type is used is different based on whether or not the supplied type parameter is a value or reference type. When a generic type is first constructed with a value type as parameter, the runtime creates a specialized generic type with the supplied parameter or parameters substituted in the appropriate places in the MSIL. Specialized generic types are created once for each of the unique value type used as parameter. For example, suppose your program code declared a Stack constructed of integers, like this: Stack stack;
At this point, the runtime generates a specialized version of the Stack class with the integer substituted appropriately as its parameter. Now, whenever your program code uses a stack of integers, the runtime reuses the generated specialized Stack class. In the following example, two instances of a stack of integers are created, and they share a single instance of the Stack code:
Stack stackOne = new Stack();
Stack stackTwo = new Stack();
However, if at another point in your program code another Stack class is created but with a different value type such as a long or a user-defined structure as its parameter, then the runtime generates another version of the generic type, this time substituting a long in the appropriate places in the MSIL. Conversions are no longer necessary because each specialized generic class natively contains the value type.
Generics work a bit differently for reference types. The first time a generic type is constructed with any reference type, the runtime creates a specialized generic type with the object references substituted for the parameters in the MSIL. Then, each time a constructed type is instantiated with a reference type as its parameter, regardless of its type, the runtime reuses the previously created specialized version of the generic type. This is possible because all references are the same size.
For example, suppose you had two reference types, a Customer class and an Order class, and that you created a stack of Customer types:
Stack customers;
At this point, the runtime generates a specialized version of the Stack class that, instead of storing data, stores object references that will be filled in later. Suppose the next line of code creates a stack of another reference type, called Order:
Stack orders = new Stack();
Unlike the value types, another specialized version of the Stack class is not created for the Order type. Rather, an instance of the specialized version of the Stack class is created and the orders variable is set to reference it. Suppose you then encountered a line of code to create a stack of a Customer type:
customers = new Stack();
As with the previous use of the Stack class created with the Order type, another instance of the specialized Stack class is created, and the pointers contained therein are set to reference an area of memory the size of a Customer type. The C# implementation of generics greatly reduces code bloat by reducing the number of specialized classes created by the compiler for generic classes of reference types to just one.
C# Generics is language features that provide support for parameterized types. C# generic type substitutions are performed at runtime and generic type information is preserved for the instantiated objects.

Conclusion
Generics are a great way of writing classes that combine reusability, type safety and efficiency. Generics are commonly used with collections. .NET 2.0 has introduced a new namespace called System.Collections.Generic which contains classes that support generics.

Which Versions of the .NET Framework Support Generics?
Generics are only supported on version 2.0 and above of the Microsoft .NET framework, as well as version 2.0 of the compact framework.

Can I Use Generics in Web Services?
Unfortunately, no. Web services have to expose a WSDL-based contract. Such contracts are always limited by the expressiveness of the message format being used. For example, HTTP-GET based web services only support primitive types such as int or string, but not complex types like a DataSet. SOAP-based web services are more capable, but SOAP has no ability to represent generic type parameters. As a result, at present, you cannot define web services that rely on generic types. That said, you can define .NET web services that rely on closed constructed generic types, for example: \

[C#]
public class MyWebService
{
[WebMethod]
public List GetCities()
{
List cities = new List();
cities.Add("New York");
cities.Add("San Francisco");
cities.Add("London");
return cities;
}
}
In the above example, List will be marshaled as an array of strings.

Can I Use Generics in Enterprise Services?
Unfortunately, no. All methods and interfaces on a ServicedComponent-derived class must be COM-visible. The COM type system is IDL, and IDL does not support type parameters.

Can I Use Generics in Indigo?
Unfortunately, no. SOAP has no ability to represent generic type parameters, and so all methods and interfaces on an indigo service contract or service class can only use primitive types such as integers or strings, or specific known types that provide a data contract. As a result, at present, you cannot define Indigo services that rely on generic types, that is, services that leave it up to the service consumer to specify the types to use when invoking the service.

Can I Use Generics in .NET Remoting?
Yes. You can expose generic types as remote objects

Where Does the .NET Framework Itself Use Generics?
Version 2.0 of the .NET Framework makes use of generics in three main areas: The System namespace added a large set of static generic methods to the Array type. These methods automate and streamline common manipulations of and interactions with arrays. The System namespace also defined a number of generic utility delegates, which are used by the Array type and the List class, but can be used freely in other contexts as well. In addition, System provides support for nullable types. The System namespace defines the IComparable interface and the EventHandler delegate, both generic reincarnations of their non-generic predecessors. The System namespace also defines the IEquatable interface, used to check for equality of two values. The System namespace defines the ArraySegment used to allocate a strongly typed portion of an array.
The System.Collections.Generic namespace defines generic collection interfaces, collections and iterator classes, similar to the old, non generic ones available in the System.Collections namespace. The System.Collections.Generic namespace also defines a few generic helper classes and structures.
The System.ComponentModel namespace defines the class BindingList. A binding list is used very similar to a mere generic list, except it can fire events notifying interested parties about changes to its state.
The System.Collections.ObjectModel namespace defines a few types such as Collection that can be used as base types for custom collections.
Finally, all the types that supported IComparable in .NET 1.1 support IComparable and IEquatable in .NET 2.0. This enables you to use common types for keys, such as int, string, Version, Guid, DateTime, and so on.

What Are the Generic Collection Classes?
The System.Collections.Generic namespace contains the majority of the new generic collections. These collections are by and large the generic reincarnation of the collections available in the System.Collections namespace. For example, there is a generic Stack and a generic Queue classes. The collections in System.Collections.Generic are used in much the same way as their predecessors. In addition, some of the collections where renamed in the process. The Dictionary data structure is equivalent to the non-generic HashTable, and the class List is analogous to the non-generic ArrayList. System.Collections.Generic also defines new types that have no equivalent in System.Collections, such as LinkedList and KeyValuePair. In addition, The System.Collections.Generic namespace defines generic interfaces such as ICollection and IList. To support generic-based iterators, System.Collections.Generic defines the IEnumerable and IEnumerator interfaces, and these interfaces are supported by all the generic collections. It is important to note that the generic collections can be used by clients that do not rely on generics, because all the generic collections also support the non-generic collection and iteration interfaces (IList, ICollection, IEnumerable). For example, here is the definition of the List class:
[C#]
public class List : IList,IList
{...}

What Are the Generic Methods of System.Array?
The System.Array type is extended with many generic static methods. The generic static methods are designed to automate and streamline common tasks of working with arrays, such as iterating over the array and performing an action on each element, scanning the array looking for a value that matches a certain criteria (a predicate), converting and sorting the array, and so on. Below is a partial listing of these static methods:
[C#]
public abstract class Array
{
//Partial listing of the static methods:
public static ReadOnlyCollection AsReadOnly(T[] array);
public static int BinarySearch(T[] array,T value);
public static int BinarySearch(T[] array,T value,
IComparer comparer);
public static U[] ConvertAll(T[] array,
Converter converter);
public static bool Exists(T[] array,Predicate match);
public static T Find(T[] array,Predicate match);
public static T[] FindAll(T[] array,Predicate match);
public static int FindIndex(T[] array,Predicate match);
public static void ForEach(T[] array,Action action);
public static int IndexOf(T[] array,T value);
public static void Sort(T[] array,IComparer comparer);
public static void Sort(T[] array,Comparison comparison);
}

What Are the Generic Methods of List?
Besides implementing IList, the List type contains many generic helper methods. These methods are designed to automate and streamline common tasks of working with the list, such as iterating over the list and performing a task on each element, scanning the list looking for a value that matches a certain criteria (a predicate), or just searching for a particular value, converting and sorting the list, and so on. Below is a partial listing of these generic methods:
[C#]
public class List : IList,
{
//Partial listing of the generic helper methods:
public List ConvertAll(Converter converter);
public bool Exists(Predicate match);
public T Find(Predicate match);
public List FindAll(Predicate match);
public int FindIndex(Predicate match);
public T FindLast(Predicate match);
public void ForEach(Action action);
public int LastIndexOf(T item);
public void Sort(Comparison comparison);
public T[] ToArray();
//More members
}


What Are Nullable Types?
Unlike reference types, you cannot assign a null into a value type. This is often a problem when interacting with code that interprets a null as having no value, rather than no-reference. The canonical example is database null values in columns that have representation as types such as int or DateTime. To address that, the System namespace provides the structure Nullable defined as:
[C#]
public interface INullableValue
{
bool HasValue{get;}
object Value{get;}
}
[Serializable]
public struct Nullable : INullableValue,IEquatable>,... where T : struct
{
public Nullable(T value);
public bool HasValue{get;}
public T Value{get;}
public T GetValueOrDefault();
public T GetValueOrDefault(T defaultValue);
public bool Equals(Nullable other);
public static implicit operator Nullable(T value);
public static explicit operator T(Nullable value);

//More members
}

What do you mean by Function Overloading
When more than one function is created with the same name, but different is of there arguments . In other words, function names can be overloaded. A function may also have the same name as an attribute. In the case that there is an ambiguity between a function on a complex type and an attribute of the complex type, the attribute will always be used.

Can you give an example of when it would be appropriate to use a web service as opposed to a nonserviced dot NET component
When to Use Asp Net Web Services: (i)Communicating through a Firewall When building a distributed application with 100s/1000s of users spread over multiple locations, there is always the problem of communicating between client and server because of firewalls and proxy servers. Exposing your middle tier components as Web Services and invoking the directly from a Windows UI is a very valid option. (ii)Application Integration When integrating applications
written in various languages and running on disparate systems. Or even applications running on the same platform that have been written by separate vendors. (iii)Business-to-Business Integration This is an enabler for B2B intergtation which allows one to expose vital business processes to authorized supplier and customers. An example would be exposing electronic ordering and invoicing, allowing customers to send you purchase orders and suppliers to send you invoices electronically. (iv)Software Reuse This takes place at multiple levels. Code Reuse at the Source code level or binary componet-based resuse. The limiting factor here is that you can reuse the code but not the data behind it. Webservice overcome this limitation. A scenario could be when you are building an app that aggregates the functionality of serveral other Applicatons. Each of these functions could be performed by individual apps, but there is value in perhaps combining the the multiple apps to present a unifiend view in a Portal or Intranet.

Can you define basic element of WebServices and explain any one from them
These are as follows SOAP, WSDL and UDDI. And I am explaining about the SOAP(Simple Object Access Protocol) it is a communication protocol it is for communication between application it is platform and language independent.It is based on XML and also help to get from Firewall.

Explain functioning of Web Services Protocols
Http-Get:- This is standard protocol that helps client to communicate with server with HTTP.When client send a request to server via HTTP request and reuired parameter are attached with the querystring.Example:- http://www.dotnetquestion.info/dotnet/interview.aspx?id=pervej&cast=munjal and we get the value from querystring. Request.querystring("id") Request.querystring("cast"). Http-Post:-This is same as Http-Get but the diffrence is that in place of
sending parameters onto the URL information is send with HTTP request message with some extra information which contains Parameters and their values.This Protocols is limited to sending name/value pairs. SOAP:-The only diffrence is that its relies on the XML as compares to Http-Get,Http-Post.SOAP can send not only the name/value pairs but also some complex object also as for example datatypes,class,objects.SOAP can also uses request/reponse model as Http-Get,Http-post but it is not limited to Request/Response it can also send types of message.Because its uses XML that is pure text so firewalls not created so much problem because its easily converted in to HTML.

Which one is better Remoting or WebServices
Remoting involves efficient communication or exchange of data when we have control on both ends of the application involved in the communication process. Web Services is open-protocol-based exchange of informaion. Web Services play there role when we need to communicataion with external organization or whicj doesnot have .NET technology.

How .NET and non .NET component communicate with each other when they are on different platform
In past when we have to communicate .NET with non .NET component we are using COM component this component helps in doing this. At the moment we are using in both apps a COM component that has an intermediary Windows service running on one machine. But this component is quite old and not in use now because it will create a problem when we are using firewall. So to handle this we use Web-Services which really have a solution for Firewall.

What is WSDL
WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services).

What is the standard you use to wrap up a call to a Web service
HTTP with SOAP.

What is Asp Net Web Services
Web services are programmable business logic components that provide access to functionality through the Internet. Standard protocols like HTTP can be used to access them. Web services are based on the Simple Object Access Protocol (SOAP), which is an application of XML. Web services are given the .asmx extension.

Define Protocols that helps Web Services in Asp Net
Web Services used three protocols for interacting with the clients:-
Http-Post
Http-Get
SOAP

What are VSDISCO files
VSDISCO files are DISCO files that enable dynamic discovery of Web Services. ASP.NET links the VSDISCO to a HTTP handler that scans the host directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.

What is UDDI
UDDI stands for Universal Description, Discovery, and Integration. It is like an "Yellow Pages" for Web Services. It is maintained by Microsoft, IBM, and Ariba, and is designed to provide detailed information regarding registered Web Services for all vendors. The UDDI can be queried for specific Web Services.


How to Create Virtual Directory
1. Click ?Start೥ttings࣯ntrol Panel ?ministrative Toolsą©®ternet information services?
2. Expand Internet Information Server.
3. Expand the server name.
4. In the left pane, right-click Default Web Site, point to New, and then click Virtual Directory.
5. In the first screen of the New Virtual Directory Wizard, type an alias, or name, for the virtual directory (SiteName), and then click Next.
6. In the second screen, click Browse. Locate the content folder that you created to hold the Web content. Click Next.
7. In the third screen, click to select Read and Run scripts (such as ASP). Make sure that the other check boxes are cleared. Click Finish to complete the wizard.

Diffrence between Viewstate and Session
View State are valid mainly during postbacks and information is stored in client only. Viewstate are valid for serializable data only. Moreover Viewstate are not secured as data is exposed to client. although we can configure page directive and machine key to make view state encrypted. Where in case of session this is user specific data that is stored in server memory . Session state is valid for any type of objects. We can take help of session  through different web pages also


Is it possible to get vale of viewstate value on next page
View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name,__POSTBACK . This field is embedded only when there is an IButtonControl on the page and its PostBackUrl property is set to a non-null value. This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

Page poster = this.PreviousPage;
we can find any control from the previous page and read its state:
Label posterLabel = poster.findControl("myLabel");
string lbl = posterLabel.Text;
Cross-page post back feature also solves the problem of posting a Form to multiple pages, because each control, in theory, can point to different post back URL

How to create and removethat cookies in asp.net
This is the syntax for creating a cookies.
HttpCookie SiteCookies = new HttpCookie("UserInfo");
SiteCookies["UserName"] = "Pervej";
SiteCookies["sitename"] = "dotnetRed";
SiteCookies["Expire"] = "5 Days";
SiteCookies= DateTime.Now.AddDays(5);
Response.Cookies.Add(SiteCookies);
Now syntax to remove this cookie:-
HttpCookie SiteCookies= new HttpCookie("UserInfo");
siteCookies= DateTime.Now.A
ddDays(-1);
Response.Cookies.AddSiteCookies

Server Control and User Control
An ASP.NET control (sometimes called a server control) is a server-side component that is shipped with .NET Framework.A server control is a compiled DLL file and cannot be edited. It can, however, be manipulated through its public properties at design-time or runtime. It is possible to build a custom server control (sometimes called a customcontrol or composite control). (We will build these in part 2 of this article).
In contrast, a user control will consist of previously built server controls (called constituent controls when used within a user control). It has an interface that can be completely edited and changed. It can be manipulated at design-time and runtime via properties that you are responsible for creating. While there will be a multitude of controls for every possible function built by third-party vendors for ASP.NET, they will exist in the form of compiled server controls, as mentioned above. Custom server controls may be the .NET answer to ActiveX Web controls.



Can we update table from View that we are using
No view are only virtual table so cannot update table.

How to change the Page Title dynamically
//Declare
protected System.Web.UI.HtmlControls.HtmlGenericControl Title1 ;
//In Page_Load
Title1.InnerText ="Page 1" ;

Explain session and its type
Sessions can be managed by two ways in case of webfarms:
1. Using SQL server or any other database for storing sessions regarding current logged in user.
2. Using State Server, as one dedicated server for managing sessions. State Server will run as service on web server having dotnet installed.
In ASP.NET there is three ways to manage session objects. one support the in-proc mechanism and other two's support the out-proc machanism.
1)In-Proc (By Default)
2) SQL-Server (Out-proc)
3) State-Server (Out-Proc)

Something about Session or Session Management and Application
Sessions can stored in cookies . cookieless session is also available.for cookie less session it wil create unique session id for each session. it wil be automatically retrieved in URL.state management can be like, user sessions can be stored in 3 ways .
Inproc - stored in asp.net worker process
stateserver- stored in window service .
sqlserver- user sessions can be stored in sqlserver also.Application Start This Event is fired when t
he server which holding application starts whereas Session Start event is fired when any User has access that page or Session has been created. Suppose we want to track that how many users have accessed our sites today then Application Start is the best place to do so or we want to give some personalised view to User than Session is the best place.

Which file is taken by compiler when we have both file Application and Server Configguration file
Application Configuration File Values will over ride the values of server configuration file. But only when we allow override set as True, if we does not allow override then Application Configuration file variables cannot override the values of server configuration file.


what is the difference between serializable and MarshalByRefObject
In .net Remoting if ypu want your class to be participated in remoting it has to inherit from MarshalByRefObject class so that class definition can be passed by reference Where as [seraliazable] attribute is preceded before class that is can be seralized but this is used in conjuction with MarshalByValue class. Because when we pass by value then only we require this attribute.

What is serialization in .NET and What are the ways to control serialization
Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database)Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class,including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created. Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the clipboard. You can serialize an object to a stream,disk,memory,over the network,and so forth.Remoting uses serializatn.to pass objects "by value" from one computer or application domain to another. XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data.Because XML is an open standard,it is an attractive choice for sharing data across the Web. SOAP is an open standard,which makes it an attractive choice. There are two separate mechanisms provided by the .NET class library


1.XmlSerializer
2.SoapFormatter/BinaryFormatter.

Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code.

Diffrence Between ServerSide and ClientSideCode
server side code is responsible to execute and provide the executed code to the browser at the client side. the executed code may be either in XML or Plain HTML. the executed code only have the values or the results that are executed on the server. The clients browser executes the HTML code and displays the result.
where as the client side code executes at client side and displays the result in its browser. it the client side core consist of certain functions that are to be executed on server then it places request to the server and the server responses as the result in form of HTML.



How do I make a reference type parameter as a readonly parameter
Assuming that it is, and that all the data fields are only accessible via parameters, then you can create an interface for the class that only allows access to the parameters via a get. Add this interface to the class definition, then where you need the instance of the class to be read only, access it through the interface.

How to check querystring is null or not
string queryStringVal = Request.QueryString["field"];
if (string.IsNullOrEmpty(queryStringValue))
{
}
else
{
}

What is Pull and Push Model in ado.net
Answer:- Pull model is used to pick out the element or we can also say objects from Database tabel.
Push model is used to insert the element only at the top position in table to database with the help of object. But when we have to delete the top most record pull method is used over push. Similar to stack operation

What is Property
A property is a thing that describes the features of an object. A property is a piece of data contained within class that has an exposed interface for reading/writing. Looking at that definition, you might think you could declare a public variable in a class and call it a property. While this assumption is somewhat valid, the true technical term for a public variable in a class is a field. The key difference between a field and a property is in the inclusion of an interface.
We make use of Get and Set keywords while working with properties.
We prefix the variables used within this code block with an underscore. Value is a keyword, that holds the value which is being retrieved or set.
Private _Color As String
Public Property Color()
Get
Return _Color
End Get
Set(ByVal Value)
_Color = Value
End Set
End Property

What is PostBack and Callback
One technique that current ASP.NET 1.0/1.1 developers use to overcome this postback problem is to use the Microsoft XMLHTTP ActiveX object to send requests to server-side methods from client-side JavaScript. In ASP.NET 2.0, this process has been simplified and encapsulated within the function known as the Callback Manager.
The ASP.NET 2.0 Callback Manager uses XMLHTTP behind the scenes to encapsulate the complexities in sending data to and from the servers and clients. And so, in order for the Callback Manager to work, you need a web browser that supports XMLHTTP. Microsoft Internet Explorer is, obviously, one of them.


What is the diffrence between Pivot an Unpivot
These tow are th opertor in Sql Server 2005 these are used to manupulate a expression from one table into another table but both are opposite of each other Pivot take rows and put them into the column but on the other hand Unpivot take column and put them into the row.Pivots helps in rotating unique in one column from mutliple columns.

Can you explain difference between .Net framework and .Net Compact Framework
As the name suggest to us that .Net compact framework has been created with enabling managed code on devices just like PDAs,mobiles etc. These are compact devices for which a .NET compact framework is used.This is main diffrence between these two.

What are Namespaces
The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally-unique types. Even if you do not explicitly declare one, a default namespace is created.This unnamed namespace, sometimes called the global namespace, is present in every file. Any identifier in the global namespace is available for use in a named namespace. Namespaces implicitly have public access and this is not modifiable.

How can we load multiple tables in to Dataset
Write the select queries required in fill statement.
e.g.
Adp.Fill("Select * from Table1;Select * from Table2;Select * from Table3",DS)
This statement wil generate Dataset with 3 datatables.
How to display alert on post back from javascript
string strScript = " ";
if ((!Page.IsStartupScriptRegistered("clientScript")))
{
Page.RegisterStartupScript("clientScript", strScript);
}

What is Machine.config File
As web.config file is used to configure one asp .net web application, same way Machine.config file is used to configure application according to a particular machine. That is, configuration done in machine.config file is affected on any application that runs on a particular machine. Usually, this file is not altered and only web.config is used which configuring applications.
What is a LiveLock
A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.
what is a jitter and how many types of jitters are there
JIT is just in time complier.it categorized into three:-
1 Standard JIT : prefered in webApp-----on diamand
2 Pre JIT : only one time------only use for window App
3 Economic JIT : use in mobile App


What are the different IIS level
There are mainly three level of ISS these are as follows.
(1)Low ; (2)Medium ; (3)High
(1)Low(IIS Process):-In this all the main process of IIS and ASP.NET application runs in the same process . But here is some disadvantage of this if one of process is failed whole the process failed.Its required low resources as compare to other.
(2)Medium(Pooled):-In this IIS process and application runs in different process.Let there are two proces
s process1 and process2 then in process one IIS process is running and in process2 application is run.
(3)High(Isolated):-In this all the process running in there own process. One process for one application.But it is one costly things because too much memory needed for this.

Isolation levels in SQL SERVER
Isolation level get the condition to which data is isolated for use by one process and secured against interference from other processes.
Read Committed -
SQL Server applied a share lock while reading a row into a cursor but frees the lock immediately after reading the row. Because a shared lock request is blocked by an exclusive lock, a cursor is prevented from reading a row that another task has updated but not yet committed. Read commi
tted is the default isolation level setting for both SQL Server and ODBC.
Read Uncommitted -
When no locks while reading a row into a cursor and honors no exclusive locks. Cursors can be populated with values that have already been updated but not yet committed. The user is bypassing all of SQL Server?s locking transaction control mechanisms.
Repeatable Read or Serializable -
SQL Server requests a shared lock on each row as it is read into the cursor as in READ COMMITTED, but if the cursor is opened within a transaction, the shared locks are held until the end of the transaction instead of being freed after the row is read. This has the same effect as specifying HOLDLOCK on a SELECT statement.

What does the term immutable mean
It means to create a view of data that is not modifiable and is temporary of data that is modifiable.Immutable means you can't change the currrent data,but if you perform some operation on that data, a new copy is created. The operation doesn't change the data itself. Like let's say you have a string object having "hello" value. Now if you say
temp = temp + "new value"
a new object is created, and values is saved in that. The temp object is im
mutable, and can't be changed. An object qualifies as being called immutable if its value cannot be modified once it has been created. For example, methods that appear to modify a String actually return a new String containing the modification. Developers are modifying strings all the time in their code. This may appear to the developer as mutable - but it is not. What actually happens is your string variable/object has been changed to reference a new string value containing the results of your new string value. For this very reason .NET has the System.Text.StringBuilder class. If you find it necessary to modify the actual contents of a string-like object heavily, such as in a for or foreach loop, use the System.Text.StringBuilder class.

which dll handles the request of .aspx page
When the Internet Information Service process (inetinfo.exe) receives an HTTP request, it uses the filename extension of the requested resource to determine which Internet Server Application Programming Interface (ISAPI) program to run to process the request. When request is for an ASP.NET page (.aspx file), IIS passes the request to the ISAPI DLL capable of handling the request for ASP.NET pages, which is aspnet_isapi.dll.

ASP.NET Globalization and Localization
Globalization is the process of designing and developing applications that function for multiple cultures, and localization is the process of customizing your application for a given culture and locale. The topics in this section describe how to create ASP.NET Web applications that can be adapted to different languages and cultures.

Type of garbage collector
There are two types of Garbage Collector
managed garbage collector
see we will declaring variable ,object in our programes once this kind of variable,object goes out of the scope ,they are put into the heap and they are checked for the further existence.once its beeing no longer used garbage collector wil deallcate mem for that variable and objects.
Umanaged garbage collector
this was done mannually and u will be happen to open a conn
ection with database,will be open the file etc. while this kind of the thing goes out of the scope we have to explicitly call the garage colector by calling the closecommand of the datbase once the connection is closed it puts this memmory ino the heep and process follws the same

Diffrence between function and StoreProcedure
Both functions and stored procedures can be custom defined and part of any application.Functions, on the other hand, are designed to send their output to a query or T-SQL statement. For example, User Defined Functions (UDFs) can run an executable file from SQL SELECT or an action query,while Stored Procedures (SPROC) use EXECUTE or EXEC to run. Both are instantiated using CREATE FUNCTION.stored procedures are designed to return its output to the application. A UDF returns table variables,while SPROC can't return a table variable although it can create a table. Another significant difference between them is that UDFs can't change server environment or your operating system environment, while a SPROC can. Operationally, when T-SQL encounters an error the function stops, while T-SQL will ignore an error in a SPROC and proceed to the next statement in your code (provided you've included error handling support). You'll also find that although a SPROC can be used in an XML FOR clause, a UDF cannot be.
How to get number of control on web page
foreach (Control ctrl in Page.Form.Controls)
{
Response.Write(ctrl.ID);
}

Why it is preferred not to use finalize for cleanup
Answer:-There is problem with the finalize regards to object when we use finalize to destroy the object it will take two round to remove the objects.To understand it we will take a simple example let there are three objects obj1,obj2,obj3 we use finalize for obj2.Now when garbage collector is run first time it will only clean obj1,obj3 becuase obj2 is pushes to the finalization queue. Now when garbage collector runs second time it will take if any object is pending for finalization then it will check the finalization queue if any item it will destroy that one.
What is exception handling
When an exception occurs, the system searches for the nearest catch clause that can handle the exception, as determined by the run-time type of the exception. First, the current method is searched for a lexically enclosing try statement, and the associated catch clauses of the try statement are considered in order. If that fails, the method that called the current method is searched for a lexically enclosing try statement that encloses the point of the call to the current method.This search continues until a catch clause is found that can handle the current exception, by naming an exception class that is of the same class, or a base class, of the run-time type of the exception being thrown. A catch clause that doesn't name an exception class can handle any exception.Once a matching catch clause is found, the system prepares to transfer control to the first statement of the catch clause. Before execution of the catch clause begins, the system first executes, in order, any finally clauses that were associated with try statements more nested that than the one that caught the exception.Exceptions that occur during destructor execution are worth special mention. If an exception occurs during destructor execution, and that exception is not caught, then the execution of that destructor is terminated and the destructor of the base class (if any) is called. If there is no base class or if there is no base class destructor, then the exception is discarded.



What is event bubbling
Event Bubbling is nothing but events raised by child controls is handled by the parent control. Example: Suppose consider datagrid as parent control in which there are several child controls.There can be a column of link buttons right.Each link button has click event.Instead of writing event routine for each link button write one routine for parent which will handlde the click event of the child link button events.Parent can know which child actaully triggered the event.That thru arguments passed to event routine.


Types of Directive
Directives in ASP.NET control the settings and properties of page and user control compilers. They can be included anywhere on a page, although it is standard to place them at the beginning. Directives are used in both .aspx files (ASP.NET pages) and .ascx files (user control pages). ASP.NET pages actually support eight different directives.
@ Page
@ Control
@ Import
@ Implements
@ Register
@ Assembly
@ OutputCache
@ Reference

What is correlated SubQuery
A correlated sub-query is dependent upon the outer query. The outer query and the sub-query are related typically through a WHERE statement located in the sub-query. The way acorrelated sub-query works is when a reference to the outer query is found in the sub-query, the outer query will be executed and the results returned to the sub-query.The sub-query is executed for every row that is selected by the outer query.

How to create cookies in asp.net

VB.NET
C#
HttpCookie cookie;
String UserID = "dotnetquestion";
cookie = new HttpCookie("ID");
cookie.Values.Add("ID", ID);
Response.Cookies.Add(cookie);

How many cookies can a application use
Most probaly 20 cookies are used but some browser can use even more.

What is the difference between ToString and Convert.ToString
The difference is quite simple Convert can handle the NULLS values but on the other side ToString produce error like NULL reference exception error.

BLOB Datatype in ASP.NET
BLOB data type is used to store any data that a program can generate: graphic images, satellite images, video clips, audio clips, or formatted documents saved by any word processor or spreadsheet. The database server permits any kind of data of any length in a BLOB column.
Like CLOB objects, BLOB objects are stored in whole disk pages in separate disk areas from normal row data.The advantage of the BLOB data type, as opposed to CLOB, is that it
accepts any data. Otherwise, the advantages and disadvantages of the BLOB data type are the same as for the CLOB data type.

What is AUTOEVENTWIREUP
AutoEventWireup is a Boolean attribute that indicates whether the ASP.NET pages events are auto-wired.
Note: In the above case, ASP.NET compiles the code-behind page on the fly. We have to note that this compilation step only occurs when the code-behind file is updated. Whether the file has been updated or not, well this is detected through a timestamp change.The AutoEventWireup attribute may have a value of true or false. When an ASP.NET Web Application is created by using Microsoft Visual Studio .NET, the value of the AutoEventWireup attribute is set as false.

We can specify the default value of the AutoEventWireup attribute in the following locations:
The Machine.config file.
The Web.config file.
Individual Web Forms (.aspx files).
Web User Controls (.ascx files)
The value of the AutoEventWireup attribute can be declared in the section in the Machine.config file or the Web.config file.We must not set the value of the AutoEventWireup attribute to true if performance is key consideration.If we set the value of the AutoEventWireup attribute to true, the ASP.NET page framework must make a call to the CreateDelegate method for every Web Form (.aspx page), and instead of relying on the automatic hookup, manually override the events from the page.

ArrayList in asp.net
(1)Its capacity is increased if required as objects are added to it. So it frees programmer from the worries of array overflow.
(2)Provides methods to perform common operations -- append, insert, remove, replace etc.
(3)There is no restriction on the type of objects which can be added to an arraylist. First object could be a
(4)string, second a double, third a user defined object and so on.
(5)ArrayList can be made read only after adding elements to prevent unintentional modifications.
(6)It provides an overloaded method to perform binary search on its objects.

Difference between = and ==
= is used for assignment to assign some value for example
int i

i=9;
on the other hand == is used for comparing some values

if(i==9)
























































Sub Select_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Select.Click
Dim newCookie As HttpCookie = New HttpCookie("dotnetBooks")
newCookie.Values.Add("Name", TxtBox.Text)
newCookie.Values.Add("Publisher", RadioButtonList1.SelectedItem.Text)
newCookie.Expires = #12/31/2008#
Response.Cookies.Add(newCookie)
Label3.Text = "Cookie Created"
Select.Visible = False
TxtBox.Visible = False
Label1.Visible = False
Label2.Visible = False
RadioButtonList1.Visible = False
End Sub