C#中NameValueCollection类用法 读取配置信息
NameValueCollection允许保存具有相同Key值的数据; 而Dictionary 则不允许这么做,它的Key是具有唯一性的,
HashTable 是唯一key 无序
Dictionary 是唯一key 但是可以排序
NameValueCollection key 可以重复
//第一 public NameValueCollection GetConfigKeyValue(string IPKey) { var nvc = new NameValueCollection(); try { nvc = GetIPConfigKey(IPKey); if (nvc == null) {nvc = new NameValueCollection();} } catch { nvc = new NameValueCollection(); } return nvc; } //第二 public NameValueCollection GeIPConfigKey(string IPKey) { var dt = GetIPConfig(IPKey); NameValueCollection nvc = new NameValueCollection(); foreach (DataRow dr in dt.Rows) { nvc [dr["IPName"].ToString()] = dr["IPValue"] as string; } return nvc ; } //第三 public DataTable GetIPConfig(string IPKey) { var sqlModel= new SqlModel(DBUtility.DBType.Sql) { ExecuteType = SqlExecuteType.DataTable, Sql = @" select d.* from Tab_IPDetail d inner join Tab_IPConfig c on d.Configid=c.id where c.IPKey=@IPKey ", DbParameter = new List<System.Data.Common.DbParameter>() { DBHelper.CreateInDbParameter("IPKey", IPKey) }, }; var result =DBHelper.ExecuteSqlModel<DataTable>(sqlModel); return result; }