HashTable的使用示例
发布日期:2021-06-30 19:10:40
浏览次数:3
分类:技术文章
本文共 1260 字,大约阅读时间需要 4 分钟。
using System; using System.Collections; using System.Text; public class SamplesHashtable { public static void Main() { // Create and initialize a new Hashtable. Hashtable table = new Hashtable(); //Student Name, Grade table.Add("Jay", 100); table.Add("Brian", 87); table.Add("Rajesh", 92); table.Add("Bill", 76); table.Add("Brad", 84); table.Add("Kit", 91); table.Add("Vinaya", 80); table.Add("Lakshan", 87); // Display the properties and values of the Hashtable. Console.WriteLine("Count: {0}", table.Count ); PrintTable( table ); Console.WriteLine(); int g = (int) table["Jay"]; Console.WriteLine ("Jay'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,-8} {1,-8}", "Name","Grade"); Console.WriteLine ("{0,-8} {1,-8}", "----","-----"); foreach (DictionaryEntry e in myList) { Console.WriteLine ("{0,-8} {1,-8}", 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://linuxstyle.blog.csdn.net/article/details/1539759 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月27日 10时46分31秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java http请求
2019-04-30
tensorflow 数据格式
2019-04-30
tf rnn layer
2019-04-30
tf input layer
2019-04-30
tf model create
2019-04-30
tf dense layer两种创建方式的对比和numpy实现
2019-04-30
tf initializer
2019-04-30
tf 从RNN到BERT
2019-04-30
tf keras SimpleRNN源码解析
2019-04-30
tf keras Dense源码解析
2019-04-30
tf rnn输入输出的维度和权重的维度
2019-04-30
检验是否服从同一分布
2019-04-30
tf callbacks
2019-04-30
keras、tf、numpy实现logloss对比
2019-04-30
Ubuntu20.04安装微信
2019-04-30
Restful风格的使用
2019-04-30
Swagger基础入门整合SpringBoot
2019-04-30
MyBatisPlus简单入门(SpringBoot)
2019-04-30
攻防世界web进阶区NewsCenter详解
2019-04-30
攻防世界web进阶PHP2详解
2019-04-30