Sudheer Kumar
Difference between static variable vs application variables?
By Sudheer Kumar in C# on Oct 24 2013
  • Sudheer Kumar
    Oct, 2013 24

    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.

    • 1
  • Raghvandra Shukla
    Apr, 2016 5

    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.

    • 0
  • Satyendra Kumar
    Aug, 2015 13

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

    • 0
  • shimab alam
    Feb, 2014 13

    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.

    • 0
  • K P  Singh Chundawat
    Oct, 2013 28

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

    • 0
  • K P  Singh Chundawat
    Oct, 2013 28

    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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS