用户登录  |  用户注册
首 页 ┆ 商业源码 ┆ 原创产品 ┆ 编程论坛
当前位置:PB创新网 → 文章中心 → 编程技巧 → Delphi

不要节约使用变量

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:18:24
Now, you might be wondering, what does he mean, Don''t skimp on the variables? Well, often times it is more
efficient to use variables to store results from ADO queries or from objects, and then reference the
variable as opposed to continuously referencing the object.

For example, you could do this:


If Request.QueryString("Name") = "Frank" Then
   ...
End If

If Request.QueryString("Name") = "Steve" Then
   ...
End If

Response.Write("Your name is " & Request.QueryString("Name"))
Each time you use the Request object, ASP has to go read the QueryString variable name. You can reduce
this to having to just read this once by doing the following:


Dim strName
strName = Request.QueryString("Name")

If strName = "Frank" Then
   ...
End If

If strName = "Steve" Then
   ...
End If

Response.Write("Your name is " & strName)
Plus, I personally think the above scenario is easier to read. It''s easier, I think, to mentally associate
strName to be the user''s name as opposed to associating Request.QueryString("Name") as the user''s name.
Just my two cents, though! 

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

相关文章

PB创新网【ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:15,953.13000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号