Monday, March 26, 2012

C#'s const vs. readonly

A quick synopsis on the differences between 'const' and 'readonly' in C#:
'const':
Can't be static.
Value is evaluated at compile time.
Initiailized at declaration only.

'readonly':
Can be either instance-level or static.
Value is evaluated at run time.
Can be initialized in declaration or by code in the constructor.

Handlers vs. Modules

Modules are units of code that have registered for one or more pipeline events. They perform authentication, authorization, logging, etc. There is one task that is reserved for a special module, known as a handler. The handler’s unique job is to retrieve the resource that is requested in the URL. All resources served by IIS are mapped to a handler in configuration. If the configuration mapping does not exist, requests for the resource will receive a 404 HTTP status. In addition to the configuration mapping, which takes place before the pipeline begins, the handler mapping can be changed during request execution in the MAP_REQUEST_HANDLER event. This allows scenarios such as URL rewriting to work. Handlers are notified, or executed, in the EXECUTE_REQUEST_HANDLER step. (Note that only the mapped handler is notified, as you would expect.)

What is an application domain?

An application domain is the CLR equivalent of an operation system’s
process. An application domain is used to isolate applications from one
another. This is the same way an operating system process works. The
separation is required so that applications do not affect one another.
This separation is achieved by making sure than any given unique
virtual address space runs exactly one application and scopes the
resources for the process or application domain using that address space.

What are Object Initializers?

The Object initializers are the features for programming concepts which was introduced in C#.Net.

The aim of using Object Initializers is to initializing the accessible fields or properties
of an object without the need to write any parametrized constructor or separate
statements.

Sample:

using System;
class Student
{
int rollno;
string stdName;
static void Main()
{
Student s = new Student(){rollno=1,stdName="Ramesh" }; //Object Initializer
}
}

What is the purpose of IIS application pools?

We use application pools for isolation purpose. Every application within an application pool used the same worker process. Each worker process operates as a separate instance of the worker process executable, W3wp.exe, the worker process that services one application pool is separated from the worker process that services another.

In simplest words we use application pools for ISOLATION purpose.

Tuesday, March 20, 2012

Constructor in C#

  • A constructor is a special method whose task is to initialize the object of its class.
  • It is special because its name is the same as the class name.
  • They do not have return types, not even void and therefore they cannot return values.
  • They cannot be inherited, though a derived class can call the base class constructor.
  • Constructor is invoked whenever an object of its associated class is created.
  • Note: There is always atleast one constructor in every class. If you do not write a constructor, C# automatically provides one for you, this is called default constructor. Eg: class A, default constructor is A().

this Keyword in ASP.NET

this Keyword

Each object has a reference “this” which points to itself.

Two uses of this keyword.

o Can be used to refer to the current object.

o It can also be used by one constructor to explicitly invoke another constructor of the same class.