c# SortedList的使用
来源:互联网 发布:ps合成照片软件 编辑:程序博客网 时间:2024/04/28 20:49
对IDictionary进行操作是,发现用SortedList也可以等同于 ArryList和Hashtable的结合,只是通过Key排序,key不允许为空和null
value可以,在效率上没有测试,但是保证是低,必定在插入时要比较排序。
通过公用方法得到信息(得到1行数据):
- public IDictionary ExecuteDictionary( IDbCommand iCmd )
- {
- IDataReader reader = null;
- try
- {
- //只读取一行数据,第一行
- reader = iCmd.ExecuteReader( CommandBehavior.SingleRow );
- }
- catch(Exception e)
- {
- this.Close( iCmd );
- return null;
- }
- IDictionary dict = null;
- if(reader.Read())
- {
- int fieldCount = reader.FieldCount;
- dict = new SortedList( fieldCount );
- for(int i = 0; i < fieldCount; i++)
- {
- dict [reader.GetName( i ).ToLower()] = reader.GetValue( i );
- }
- }
- reader.Close();
- reader.Dispose();
- return dict;
- }
- //返回list
- public SortedList selectSingln()
- {
- DB.CommandText = @" SELECT TOP 5 * FROM products";
- DB.CommandType = CommandType.Text;
- return (SortedList)DB.ExecuteDictionary();
- }
- //遍历list
- private void _BeginRun()
- {
- _SqlServerLogic logic = new _SqlServerLogic();
- SortedList dic = logic.selectSingln();
- Hashtable hash = new Hashtable();
- //遍历sortlist
- foreach(DictionaryEntry entry in dic)
- {
- Response.Write( entry.Key + "***" + entry.Value + "<br>" );
- if( !string.IsNullOrEmpty( entry.Value.ToString() ) )
- {
- hash.Add( entry.Key, entry.Value );
- }
- }
- IDictionaryEnumerator item = hash.GetEnumerator();
- //遍历Hashtable
- while( item.MoveNext() )
- {
- Response.Write( item.Key +"-----"+ item.Value +"<br/>" );
- }
- string [] ary = new string [dic.Count];
- dic.Keys.CopyTo( ary, 0 );
- Response.Write( string.Join( ",", ary ) );
- //for 遍历list
- for(int i = 0; i < dic.Count; i++)
- {
- Response.Write( dic.GetKey(i)+"----"+ dic.GetByIndex(i) +"<br/>" );
- }
- }
- c# SortedList的使用
- C#中SortedList类的使用
- SortedList的使用举例
- C# SortedList
- C# 中使用有序表SortedList
- c# SortedList的妙用 (GroupBy)
- 使用SortedList类建立排序的DropDownList
- C# SortedList类介绍
- C# Queue Stack SortedList
- C#集合之SortedList
- C# Dictionary, SortedDictionary, SortedList
- C#学习 SortedList
- C# 排序列表(SortedList)
- C#之SortedList学习案例
- C# SortedList 键值对排序。
- C# List和SortedList简介
- SortedList
- SortedList
- 第三方支付发展趋势与分析
- 手机维修基础 常见故障分析㈠
- Java调用BAT
- 基于UML和ASP.NET实现三层B/S结构系统开发
- 手机维修基础 常见故障分析㈡
- c# SortedList的使用
- Android 实例-个人理财工具 之二 启动时初始化数据
- oracle外连接
- String StringBuffer StringBuilder
- Gridview控件中,实现插入新记录的操作(footer)
- 视频格式转化为FLV (C#)
- 手机维修基础 常见故障分析㈢
- 坏情绪是一切疾病的总根源
- Export of Yiwu commodities to Russia and Brazil increases steadily