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]; } } }
算是入门级吧。
精彩图集
精彩文章
热门标签
INSERT_INTO_
获取主机名称
js改变背景图片
值不同的列
AVL树
exls
分割大文件
Httperr.Log
广播
通信模
Banner
类型
多态
原因分析
文件夹大小
object转数组
-bash
SetLocale
用户管理
阿里云主机
证书加密
console.log
三元表达式
字符串位置
组件
sae
velocity
ARP攻击
无法复制文件
bat
常常出现的
淡入
perl
jquery解析json
Slic
马赛克
增加账户
生命周期
$符
主键
youtube视频
上传视频
通过Socket
无用
httpclient
temp
屏幕快照
所有颜色值
python线程
Linux集群
采集器
系统分享
高效随机
yii
类变量
python函数调用
集合运算符
c语言http请求
配置心得
变量的值
赞助商链接
@CopyRight 2002-2008, 1SOHU.COM, Inc. All Rights Reserved QQ:1010969229