HttpValueCollection和NameValueCollection [英] HttpValueCollection and NameValueCollection

查看:74
本文介绍了HttpValueCollection和NameValueCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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&param2=value2"
        Console.WriteLine(values.ToString());
    }
}

这篇关于HttpValueCollection和NameValueCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆