zoukankan      html  css  js  c++  java
  • C#HashTable

    //引入命名空间
    using System.Collections
    //Hash对象
    Hashtable hash=new Hashtable();
    //hash由键和值组成
    
    
    //HashTest.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                Hashtable hash = new Hashtable();
                //添加数据
                hash.Add(1, "lin");
                hash.Add(2, "bai");
                hash.Add(3, "chuan");
                //访问数据,采用键的方式访问
                Console.WriteLine(hash[1]);
                //采用遍历键集合访问数据
                //var是推断类型,可根据所获得的数据类型进行匹配对应
                var skeys = hash.Keys;  //获取hash键的集合
                foreach (object o in skeys)
                {
                    Console.WriteLine("键:{0},值:{1}", o, hash[o]);    //从下往上的方式输出
                }
                //采用遍历器
                var ie = hash.GetEnumerator();//获取一个遍历器
                while (ie.MoveNext())  //从当前行开始读起,依次遍历集合的数据,类似游标
                {
                    Console.WriteLine("键:{0},值:{1}", ie.Key, ie.Value);
                }
            }
        }
    }
  • 相关阅读:
    Ansible中文权威指南学习
    gitlab
    Python-Day01-task
    Python-Day01
    CentOs6.7 python2.6升级到2.7.11
    网站访问慢排查方法及解决方案
    LAMP环境下zabbix安装配置
    监控知识点概述
    Java抽象类、接口和内部类
    Java 访问控制
  • 原文地址:https://www.cnblogs.com/god-for-speed/p/11445082.html
Copyright © 2011-2022 走看看