Interview Tips Interview Tips, Interview Questions and Answers

21Sep/100

Optional Parameters in C#4.0

Support for optional parameters allows you to give a method parameter a default value so that you do not have to specify it every time you call the method. This comes in handy when you have overloaded methods that are chained together.
The Old Way
public void Process( string data )
{
Process( data, false );
}

public void Process( string data, bool ignoreWS )
{
Process( data, ignoreWS, null );
}

public void Process( string data, bool ignoreWS, ArrayList moreData )
{
// Actual work done here
}

The reason for overloading Process in this way is to avoid always having to include "false, null" in the third method call. Suppose 99% of the time there will not be 'moreData' provided. It seems ridiculous to type and pass null so many times.

// These 3 calls are equivalent
Process( "foo", false, null );
Process( "foo", false );
Process( "foo" );

The New Way
public void Process( string data, bool ignoreWS = false, ArrayList moreData = null )
{
// Actual work done here
}
// Note: data must always be provided because it does not have a default value

17Feb/100

ASP.NET Interview Questions: Query Strings

A query string is information sent to the server appended to the end of a page URL.
Following are the benefits of using query string for state management:-
. No server resources are required. The query string containing in the HTTP requests for a specific URL.
. All browsers support query strings.
Following are limitations of query string:-
. Query string data is directly visible to user thus leading to security problems.-
. Most browsers and client devices impose a 255-character limit on URL length.
Below is a sample "Login" query string passed in URL http://www.jack-fx.com.com/login.asp?login=testing.
This query string data can then be requested later by using Request.QueryString("login").

(I) What is Absolute and Sliding expiration?

Absolute Expiration allows you to specify the duration of the cache, starting from the time the cache is activated. The following example shows that the cache has a cache dependency specified, as well as an expiration time of one minute.

Cache. Insert ("announcement", announcement, depends, _
DateTime.Now.AddMinutes(1), Nothing)

Sliding Expiration specifies that the cache will expire if a request is not made within a specified duration. Sliding expiration policy is useful whenever you have a large number of items that need to be cached, because this policy enables you to keep only the most frequently accessed items in memory. For example, the following code specifies that the cache will have a sliding duration of one minute. If a request is made 59 seconds after the cache is accessed, the validity of the cache would be reset to another minute:

Cache.Insert("announcement", announcement, depends, _
Date Time. Max Value, _
TimeSpan.FromMinutes(1))