Thursday 24 May 2012

Static Variable in .net

It is very common requirement to share some information between all users in any web based applications. In Asp.net you can achieve this either from Application object or Static Object.
Both Static variable and Application objects stores data for whole life of the applications, you can say they behave like a global application variable.

Static methods gives you a better way to share any value or instance between all users rather than Application objects. Static properties maintain their values throughout the Application.
Static properties are working similar to your application object. Statics objects are fast because

  • No need to cast them & -
  • They are not looking for value in a collection.
Application objects are stored in application directory. The main purpose of Application object in Asp.net is for support the backward compatibility with classic asp code.

No comments:

Post a Comment