zoukankan      html  css  js  c++  java
  • NameValueCollection详解

    1.NameValueCollection类集合是基于 NameObjectCollectionBase 类。
    但与 NameObjectCollectionBase 不同,该类在一个键下存储多个字符串值(就是键相同,值就连接起来如下例子)。该类可用于标头、查询字符串和窗体数据。
    每个元素都是一个键/值对。NameValueCollection 的容量是 NameValueCollection 可以保存的元素数。
    NameValueCollection 的默认初始容量为零。随着向 NameValueCollection 中添加元素,容量通过重新分配按需自动增加。
    如下例子:

    NameValueCollection myCol = new NameValueCollection(); 
                myCol.Add("red", "rojo");//如果键值red相同结果合并 rojo,rouge 
                myCol.Add("green", "verde"); 
                myCol.Add("blue", "azul"); 
                myCol.Add("red", "rouge"); 

    2.NameValueCollection与Hashtable的区别
    a.引用区别

    hashtable:using System.Collections;

    NameValueCollection:using System.Collections.Specialized;

    b.键是否重复

    NameValueCollection:允许重复.

    HashTable是键-值集合,但键不能出现重复.


    Hashtable ht = new Hashtable(); 
    ht.Add("key","value"); 
    ht.Add("key", "value1"); //出错 
    ht["key"] = "value1"; //正确

    转自http://www.cnblogs.com/mrray/archive/2011/09/28/2193831.html

  • 相关阅读:
    python3 urllib 类
    python 金角大王博客园学习地址
    配置文件一mapper.xml
    配置文件一mybatis-config.xml
    配置文件一applicationContext.xml
    类文件路径一classpath
    配置文件一web.xml
    日志框架一logback配置和使用
    SpringBoot + redis实现分布式session共享
    SpringBoot集成Redis 一 分布式锁 与 缓存
  • 原文地址:https://www.cnblogs.com/streetpasser/p/3419070.html
Copyright © 2011-2022 走看看