6
Reply

Difference between static variable vs application variables?

Sudheer Kumar

Sudheer Kumar

Oct 24, 2013
8.2k
0

    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.

    Sudheer Kumar
    October 24, 2013
    1

    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.

    Raghvandra Shukla
    April 05, 2016
    0

    @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.

    Satyendra Kumar
    August 13, 2015
    0

    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.

    shimab alam
    February 13, 2014
    0

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

    K P Singh Chundawat
    October 28, 2013
    0

    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

    K P Singh Chundawat
    October 28, 2013
    0