6
Reply

Difference between static variable vs application variables?

Sudheer Kumar

Sudheer Kumar

11y
8.2k
0
Reply

    application variables are stored at application level and also can be accessed at application-level.

    but static varaiables are session-oriented and also can be access at session-level.

    From Performance point of view I will prefer static, because static variables provide type safety.Compile time error check for wrong values also makes static variables better than application variables.When it comes to locking Application variables are better choice, because Applicatin.Lock method will lock all application variables, whereas in case of static separate synchronization logic is required for every variable. But if you want to lock only one application level values static wins over application variables.Last but not the least, application variables wins when it comes to migration from classic asp to Asp.net because classic asp won’t have support for static variables.

    @SudheerKumar, are you sure static variable data will be available to only for same session? I think scope of static variable will be for whole application.

    Static variables is faster than application variables 1.It is not storing data in collection 2.No need to cast object in compare to application variables.

    http://stackoverflow.com/questions/10960695/using-static-variables-instead-of-application-state-in-asp-net

    If you only have one of those, there is little difference.If you have several, you should use static variables rather than Application variables. The Application.Lock method will lock all Application variables, while you can use separate synchronization identifiers for your static variables, so that each lock only affects the code that accesses that specific variable. more details visit http://stackoverflow.com/questions/894036/what-is-better-static-variable-v-s-asp-net-application-session