c#
c# hashtable -凯发ag旗舰厅登录网址下载
hashtable 注意:用foreach { /// /// the main entry point for the application. /// [stathread] static void main(string[] args) { // create and initialize a new hashtable. hashtable table = new hashtable(); //student name, grade table.add("leiwanjun", 100); table.add("wanghuan", 87); table.add("wuhailong", 92); table.add("renyao", 76); table.add("tanghonglei", 84); table.add("chenxiaoping", 91); table.add("liupeixun", 80); table.add("huyoumou", 87); // display the properties and values of the hashtable. console.writeline("count: {0}", table.count); printtable(table); console.writeline(); int g = (int) table["wuhailong"]; console.writeline ("wuhailong's grade is: {0}", g); console.writeline(); printitems ("all names", table.keys); console.writeline(); printitems ("all grades", table.values); } public static void printtable( hashtable mylist) { console.writeline ("{0, -15} {1, -15}", "name","grade"); console.writeline ("{0, -15} {1, -15}", "----","-----"); // // 排序 // arraylist al = new arraylist(mylist.keys); // al.sort(); // foreach (string name in al) // { // console.writeline("{0, -15} {1, -15}", name, mylist[name]); // } // // //遍历哈希表中的每个元素,直接输出 foreach (dictionaryentry e in mylist) { console.writeline ("{0, -15} {1, -15}", e.key, e.value); } } public static void printitems(string title, ienumerable mylist ) { console.write ("{0}: ", title); stringbuilder sb = new stringbuilder(); foreach (object o in mylist) { sb.appendformat( "{0}, ", o); } sb.remove(sb.length - 2, 2); console.writeline(sb); |
转载于:https://www.cnblogs.com/hyfei0315/archive/2008/07/07/1237728.html
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的c# hashtable的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇: jsp上传组件
- 下一篇: