问题描述
请求[钥匙]
VS Request.Params [钥匙]
VS 的Request.QueryString [钥匙]
哪种方法,你经验丰富的程序员使用?为什么?
Which method do you seasoned programmers use? and why?
推荐答案
我建议的Request.QueryString [钥匙]
。没有很大的差异,以请求[钥匙]
的查询字符串但如果你试图从值大(ER)的区别 ServerVariables
。 请求[钥匙]
会在查询字符串
值如果为null,它着眼于表格
,那么饼干
最后 ServerVariables
。
I recommend Request.QueryString["key"]
. There isn't a lot of difference to Request["Key"]
for a query string but there is a big(er) difference if you are trying to get the value from ServerVariables
. Request["Key"]
looks for a value in QueryString
if null, it looks at Form
, then Cookie
and finally ServerVariables
.
使用 PARAMS
是最昂贵的。到PARAMS第一个请求创建一个新的的NameValueCollection
键,把每个查询字符串
,表单,
饼干
和 ServerVariables
到此集合。对于第二个请求上它比更好的性能要求[钥匙]
。
Using
Params
is the most costly. The first request to params creates a new NameValueCollection
and adds each of the QueryString
, Form
, Cookie
and ServerVariables
to this collection. For the second request on it is more performant than Request["Key"]
.
说了这么多了几个关键的性能差异是相当微不足道。这里的关键是code应显示意图,并使用
的Request.QueryString
讲清楚你的意图是什么。
Having said that the performance difference for a couple of keys is fairly negligable. The key here is code should show intent and using
Request.QueryString
makes it clear what your intent is.
这篇关于请求["键"] VS Request.Params ["键"] VS的Request.QueryString ["键"]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!