Friday, February 26, 2010

Difference b/w UDFs and Stored Procedures

1>Procedure can return zero or n values whereas function can return one value which is mandatory.
2>Procedures can have input,output parameters for it whereas functions can have only input parameters.
3>Procedure allow select as well as DML statement in it whereas function allow only select statement in it.
4>Functions can be called from procedure whereas procedures cannot be called from function.
5>Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
6>We can go for transaction management in procedure whereas we can't go in function.
7>Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.

Wednesday, February 3, 2010

Static Constructor limitations

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
C Obj = new C();
C.C1();
Console.ReadKey();
}
}

public static class DHINESH
{
static DHINESH()
{
DHINESH1();
}

static void DHINESH1()
{

}
}

public class A
{
public A()
{
Console.WriteLine("This is A");
}

static A()
{
Console.WriteLine("This is static A");
}
}

public class B : A
{
public B()
{
Console.WriteLine("This is B");
}

static B()
{
Console.WriteLine("This is static B");
}
}

public class C : B
{
public C()
{
Console.WriteLine("This is C");
}

static C()
{
Console.WriteLine("This is static C");
}

public static void C1()
{

}
}
}


Result:
-->When we instantiate a Class like this C Obj = new C();

The output is :


This is static C
This is static B
This is static A
This is A
This is B
This is C

-->When we instantiate a Class like this

C Obj = new C();
C Obj1 = new C();

The output is :


This is static C
This is static B
This is static A
This is A
This is B
This is C
This is A
This is B
This is C

-->When we call a static method like this C.C1();

The output is:

This is static C

Limitations of Static constructor:

1. We cannot specify access modifier.
2. We cannot use any parameter.
3. Static constructor will be executing only once and also very first instance of the class.
4. When any static method of the class is being called the static constructor will be executing at first call itself.
5.We can use only static members or variables inside the static constructor.

Tuesday, February 2, 2010

How to restrict back button in asp.net.

We have come across the problem while clicking on the back button in the browser.

we shouldn't load the page again when we click on the back button.

Below code it will hide the back button. This is also one of the security leavl have to

follow in the transaction pages.

Response.Buffer = true;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));

Design Patterns

Creational Patterns:

Abstract Factory: Creates an instance of several families of classes
Builder: Separates object construction from its representation
Factory Method: Creates an instance of several derived classes
Prototype: A fully initialized instance to be copied or cloned
Singleton: A class of which only a single instance can exist

Structural Patterns:

Adapter: Match interfaces of different classes
Bridge: Separates an object’s interface from its implementation
Composite: A tree structure of simple and composite objects
Decorator: Add responsibilities to objects dynamically
Facade: A single class that represents an entire subsystem
Flyweight: A fine-grained instance used for efficient sharing
Proxy: An object representing another object

Behavioral Patterns:

Chain of Resp: A way of passing a request between a chain of objects
Command: Encapsulate a command request as an object
Interpreter: A way to include language elements in a program
Iterator: Sequentially access the elements of a collection
Mediator: Defines simplified communication between classes
Memento: Capture and restore an object's internal state
Observer: A way of notifying change to a number of classes
State: Alter an object's behavior when its state changes
Strategy: Encapsulates an algorithm inside a class
Template: Method Defer the exact steps of an algorithm to a subclass
Visitor: Defines a new operation to a class without change