键值对(字典)的学习笔记。5.31

using System;
using System.Collections;
using System.Collections.Generic;

namespace 字典
{
    class Program
    {
        static void Main(string[] args)
        {
            //键值对(可以看成索引下标可以自己定义的列表)
            //无法遍历?可以用foreach分别遍历它的key和value
            //key只有一个,value可以重复
            Hashtable table = new Hashtable();
            table.Add(1, 1); //前一个是键,后一个是值
            table.Add(true, 2);
            table.Remove(true);

            table.ContainsKey(1);//返回一个bool类型的值
            int a = table.Count;//长度

            //泛型字典
            Dictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "qwer");
            dic.Add(2, "1234");

            Console.WriteLine();
            Console.ReadKey();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40620756/article/details/80520250