Replace Application with .NET static variables, faster.

zhaozj2021-02-16  51

In the traditional ASP, we have to store variables applied to the entire Application with Application objects. This of course will bring the cost of memory consumption. In .NET, we can use Static variables to improve it, using Static variables in most of the time stored faster than Application objects.

practice:

Create a WebApplication, assume that name is WebApplication1, add a static member sgreeting in the Global class in Global.aspx.

Public Class Global: System.Web.httpApplication

{

Public static string sgreeting = "China is great!";

......

} Add a Label in WebForm1, named Label1.

Assign the TEXT attribute for Label1 in Page_Load ().

Private void page_load (object sender, system.eventargs e) {label1.text = WebApplication1.global.sgreeting;}

CHINA IS Great will be seen after running the program!

转载请注明原文地址:https://www.9cbs.com/read-27466.html

New Post(0)