Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Wednesday, July 16, 2008

Microsoft .Net Interview Questions and Answers 8

What is the Differnce Between Response.write & response.output.Write
In ASP.NET the Response object is of type HttpResponse and when you say Response.Write you’re really saying (basically) HttpContext.Current.Response.Write and calling one of the many overloaded Write methods of HttpResponse.
Response.Write then calls .Write() on it’s internal TextWriter object:
public void Write(object obj){ this._writer.Write(obj);}
HttpResponse also has a Property called Output that is of type, yes, TextWriter, so:
public TextWriter get_Output(){ return this._writer; }
Which means you can to the Response whatever a TextWriter will let you. Now, TextWriters support a Write() method ala String.Format, so you can do this:
Response.Output.Write(”Scott is {0} at {1:d}”, “cool”,DateTime.Now);
But internally, of course, this this is happening:
public virtual void Write(string format, params object[] arg)
{
this.Write(string.Format(format, arg));
}

Which dll is required to translate XML to SQL in IIS ?
Microsoft.data.sqlxml.dll

What is an interface and what is an abstract class? Please, expand by examples of using both. Explain why.
Answers1:
In a interface class, all methods are abstract without implementation where as in an abstract class some methods we can define concrete. In interface, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. Interface and abstract class are basically a set of rules which u have to follow in case u r using them(inheriting them).

Answers2:
Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented. One key difference between abstract classes and interfaces is that a class may implement an unlimited number of interfaces, but may inherit from only one abstract (or any other kind of) class. A class that is derived from an abstract class may still implement interfaces. Abstract classes are useful when creating components because they allow you specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. They also version well, because if additional functionality is needed in derived classes, it can be added to the base class without breaking code.

Answers3:
Abstract Classes
An abstract class is the one that is not used to create objects. An abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built. Abstract classes are similar to interfaces. After declaring an abstract class, it cannot be instantiated on it’s own, it must be inherited. Like interfaces, abstract classes can specify members that must be implemented in inheriting classes. Unlike interfaces, a class can inherit only one abstract class. Abstract classes can only specify members that should be implemented by all inheriting classes.

Answers4:
An interface looks like a class, but has no implementation. They’re great for putting together plug-n-play like architectures where components can be interchanged at will. Think Firefox Plug-in extension implementation. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.

Answers5:
One additional key difference between interfaces and abstract classes (possibly the most important one) is that multiple interfaces can be implemented by a class, but only one abstract class can be inherited by any single class.
Some background on this: C++ supports multiple inheritance, but C# does not. Multiple inheritance in C++ has always be controversial, because the resolution of multiple inherited implementations of the same method from different base classes is hard to control and anticipate. C# decided to avoid this problem by allowing a class to implement multiple interfaces, which do not contain method implementations, but restricting a class to have at most a single parent class. Although this can result in redundant implementations of the same method when different classes implement the same interface, it is still an excellent compromise.
Another difference between interfaces and abstract classes is that an interface can be implemented by an abstract class, but no class, abstract or otherwise, can be inherited by an interface.

Answers6:
What is an Abstract class?
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
What is an Interface?
An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.

What is serialization, how it works in .NET?
Serialization is when you persist the state of an object to a storage medium so an exact copy can be re-created at a later stage.
Serialization is used to save session state in ASP.NET.
Serialization is to copy objects to the Clipboard in Windows Forms
Serialization is used by remoting to pass objects by value from one application domain to another

What should one do to make class serializable?
Answers1:
To make a class serializable is to mark it with the Serializable attribute as follows.
[Serializable]
public class MyObject {
public int n1 = 0;
public int n2 = 0;
public String str = null;
}

What exactly is being serialized when you perform serialization?
The object’s state (values)

How does output caching work in ASP.NET?
Output caching is a powerful technique that increases request/response throughput by caching the content generated from dynamic pages. Output caching is enabled by default, but output from any given response is not cached unless explicit action is taken to make the response cacheable.
To make a response eligible for output caching, it must have a valid expiration/validation policy and public cache visibility. This can be done using either the low-level OutputCache API or the high-level @ OutputCache directive. When output caching is enabled, an output cache entry is created on the first GET request to the page. Subsequent GET or HEAD requests are served from the output cache entry until the cached request expires.
The output cache also supports variations of cached GET or POST name/value pairs.
The output cache respects the expiration and validation policies for pages. If a page is in the output cache and has been marked with an expiration policy that indicates that the page expires 60 minutes from the time it is cached, the page is removed from the output cache after 60 minutes. If another request is received after that time, the page code is executed and the page can be cached again. This type of expiration policy is called absolute expiration - a page is valid until a certain time.

What is connection pooling and how do you make your application use it?
Opening database connection is a time consuming operation.
Connection pooling increases the performance of the applications by reusing the active database connections instead of create new connection for every request.
Connection pooling Behaviour is controlled by the connection string parameters.
Follwing the the 4 parameters that control most of the connection pooling behaviour.
1. Connect Timeout
2. Max Pool Size
3. Min Pool Size
4. Pooling

No comments:

Archives