Using static variables instead of the Application object

Using static variables instead of the Application object

If you want to share a value or an object instance between all the pages of any session, you typically use the Application object. However, a good alternative is to use a public variable defined in a module (VB.NET only), or a static field/property defined in a class. Static properties maintain their values between clients request, and so work like Application variables. They are often a better choice because of their better performace (storing and reading a value can be up to 500 times faster with static variables), since they don’t require a lookup in a collection when you refer to them – as it happens for the Application object – and you don’t need to cast from Object to a specific type, as you must do with the Application variables (either implicitly or exclicitly, depending on your Option Stric settings), but you store and read a value in a variable or the right type, so no casting and boxing is ever required.

See also  5 Benefits of Using Time Tracking Software

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist