问题描述
如果我称之为
var nvc = HttpUtility.ParseQueryString("?foo=bar&baz=robots")
我拿回的NameValueCollection在那里,如果我调用toString就可以了,我回去查询字符串。
I get back a NameValueCollection where if I call ToString on it, I get back a query string.
var str = nvc.ToString(); //foo=bar&baz=robots....
如果我创建一个新的NameValueCollection,添加的东西给它,并调用它的ToString(),我没有得到一个查询字符串。
If I create a new NameValueCollection, add stuff to it, and call ToString() on it, I don't get back a query string.
var nvc= new NameValueCollection();
nvc["foo"] = "bar";
var str = nvc.ToString(); //default for Object.ToString()
也似乎没有要构建一个作为查询字符串编辑器的NameValueCollection的方法。有一?如果不是,为什么?能够编辑查询字符串是pretty有用的东西,但此功能是完全隐藏在某个对象的一个不起眼的方式大多数人甚至不知道存在。
Also there doesn't seem to be a way to construct a NameValueCollection that acts as a query string editor. Is there one? If not, why? Being able to edit query strings is a pretty useful thing, but this functionality is totally hidden away in an obscure mode of some object most people don't even know exists.
推荐答案
这是由内部 HttpValueCollection
类,它继承了的NameValueCollection 完成code>和覆盖
的ToString()
。结果 ParseQueryString()
是构建这个类唯一的公共道路。
This is done by the internal HttpValueCollection
class, which inherits NameValueCollection
and overrides ToString()
.ParseQueryString()
is the only public way to construct this class.
这篇关于NameValueCollection中编辑查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!