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表记录的方法,给两个例子的源码出来:
第一个例子:
C# Code [http://www.xueit.com]
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) {...}
第二个例子:
C# Code [http://www.xueit.com]
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]; } } }
算是入门级吧。
精彩图集
精彩文章
热门标签
系统资源
思路
double保留
sunday算法
sqlldr
定时自动重启
图片添加水印
PHP 短信平台
proxy
imail
代码性能
sqlserver服务器
文件输出
查询地理位置
经典模式
sqlite数据
透明背景
gawk
android控件
计划
统计数据
array_key_ex
新硬盘
模式窗口
安全加强
递归函数
linux下
数据分页
button
仿腾讯微博
页面后退
分子沉积模拟
关联其他
用vbs实现返回
关键字搜索
文件备份
memcach
WOODEN
JButton
php PHP Co
AJAX异步内容
php php解决 约
ibdata1
bytes2BSTR
.net
绑定事件
Shiro
安装app
found_row
数字金字塔
web.py
副
file.isdir
ajaxFileUplo
userAgent
exec
去黑边
java数组
手机配置信息
条形码输出
赞助商链接
@CopyRight 2002-2008, 1SOHU.COM, Inc. All Rights Reserved QQ:1010969229

