问题描述
HttpValueCollection
和 NameValueCollection
有什么区别?
如有可能,请举例说明.
What is the difference between HttpValueCollection
and NameValueCollection
?
If possible please explain with example.
谢谢
推荐答案
NameValueCollection
对键区分大小写,而 HttpValueCollection
不区分大小写.同样, HttpValueCollection
是一个内部类,它从 NameValueCollection
派生,您从不应该在代码中直接使用它. HttpValueCollection
的另一个属性是,当您将值添加到此集合时,它会自动对值进行url编码.
NameValueCollection
is case sensitive for the keys, HttpValueCollection
isn't. Also HttpValueCollection
is an internal class that derives from NameValueCollection
that you are never supposed to use directly in your code. Another property of HttpValueCollection
is that it automatically url encodes values when you add them to this collection.
以下是使用 HttpValueCollection
类的方法:
class Program
{
static void Main()
{
// returns an implementation of NameValueCollection
// which in fact is HttpValueCollection
var values = HttpUtility.ParseQueryString(string.Empty);
values["param1"] = "v&=+alue1";
values["param2"] = "value2";*
// prints "param1=v%26%3d%2balue1¶m2=value2"
Console.WriteLine(values.ToString());
}
}
这篇关于HttpValueCollection和NameValueCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!