当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 用.net静态变量取代Application 速度更快

ASP.NET
HTML服务器控件介绍:HtmlInputFile控件
HTML服务器控件介绍:HtmlInputHidden控件
HTML服务器控件介绍:HtmlInputImage控件
HTML服务器控件介绍:HtmlInputRadioButton控件
HTML服务器控件介绍:HtmlInputText控件
HTML服务器控件介绍:HtmlSelect控件
HTML服务器控件介绍:HtmlTable控件
HTML服务器控件介绍:HtmlTableCell控件
HTML服务器控件介绍:HtmlTableRow控件
HTML服务器控件介绍:HtmlTextArea控件
Web服务器控件:AdRotator控件
Web服务器控件:Button控件
Web服务器控件:Calendar控件
Web服务器控件:CheckBox控件
Web服务器控件:CheckBoxList控件
Web服务器控件:DropDownList控件
Web服务器控件:HyperLink控件
Web服务器控件:Image控件
Web服务器控件:ImageButton控件
Web服务器控件:Label控件

ASP.NET 中的 用.net静态变量取代Application 速度更快


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 246 ::
收藏到网摘: n/a

在传统的ASP中,我们要用application对象去存储应用于整个application的变量。这当然会带来内存消耗的代价。在.net中,我们可以用static变量来改善它,采用static变量在大多数时候存储的速度会比application对象快。

做法:

创建一个webApplication,假设名称为webApplication1,在Global.aspx中的Global类中增加一个静态的成员sGreeting.

在WebForm1中增加一个label,名称为label1.

在page_load()中为label1的text属性赋值。


privatevoidPage_Load(objectsender,System.EventArgse)
{

Label1.Text=WebApplication1.Global.sGreeting;

}

运行程序后将会看到Chinaisgreat!