C#遍历hashtable两个例子
下面分享在.NET中遍历HashTable表记录的方法,给两个例子的源码出来: 第一个例子: C# Code [http://www.xueit.com] using System; using System.Data; using System.Configuration; using System.Collections; using Syste
下面分享在.NET中遍历HashTable表记录的方法,给两个例子的源码出来:
第一个例子:

using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class PGhashtable : System.Web.UI.Page { Hashtable hstsore = new Hashtable(); protected void Page_Load(object sender, EventArgs e) { hstsore.Add("Jone", 67); hstsore.Add("Gore", 89); hstsore.Add("Tiny", 56); hstsore.Add("Big", 78); hstsore.Add("Titan", 78); hstsore.Add("Kery", 89); hstsore.Add("Bulk", 90); hstsore.Add("Hulk", 99); hstsore.Add("Mike", 87); hstsore.Add("Sery", 95); int max, min; max = Convert .ToInt16 ( hstsore["Jone"]); min =Convert .ToInt16 ( hstsore["Jone"]); foreach(DictionaryEntry de in hstsore ) { int temp = Convert.ToInt16(de.Value); if ( temp >= max) { max = temp ; } if (temp<=min) { min = temp; } } lblgdi.Text = "最高分是:" max.ToString() " 最低分是:" min.ToString(); } }
主要用到foreach (DictionaryEntry de in myHashtable) {...}
第二个例子:

using System; using System.Collections.Generic; using System.Text; using System.Collections; namespace GetSpec { class HashTableDemo { public string Get() { Hashtable hashTable = new Hashtable(); hashTable.Add(1, "wuyi"); hashTable.Add(2, "sky"); System.Windows.Forms.MessageBox.Show((string)hashTable[1]); foreach (DictionaryEntry de in hashTable) { System.Windows.Forms.MessageBox.Show(de.Key.ToString()); System.Windows.Forms.MessageBox.Show(de.Value.ToString()); } System.Collections.IDictionaryEnumerator enumerator = hashTable.GetEnumerator(); while (enumerator.MoveNext()) { System.Windows.Forms.MessageBox.Show(enumerator.Key.ToString()); System.Windows.Forms.MessageBox.Show( enumerator.Value.ToString()); } return (string)hashTable[1]; } } }
算是入门级吧。
精彩图集
精彩文章
热门标签
base64_encod
jmeter
threading
xfce
定积分
错的
cookie丢
Activ
vc6
标题栏
鼠标
解压
教
冲突
chmod
cx_freeze
store
中文参数乱码
c语言多进程
jdbctemplate
nagios飞信监控
row_count
命令历史
Web客户端访问
延时处
asp.net数据绑定
逆波兰式
快照
百
阿里云主机
同一分组
Valgrind
虚拟硬盘大小
密
主要版本
语句优化
php PHP判断
ora28547
更新app
人脸识别
缩略图
window
误删文件
bz2
js验证IP
两张表
case语句
不完全
百万条
数据库镜像
datatables
超级连接
normal模式
C++算法
popen()
unescape
WebDriver
插入
网卡
ODBC
赞助商链接
@CopyRight 2002-2008, 1SOHU.COM, Inc. All Rights Reserved QQ:1010969229