zoukankan      html  css  js  c++  java
  • C# 字典常用方法

    /*
                   #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
    
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Dictionary
    * Created:  2017/5/2 
    * Author:   ShangHai WangYuChen
    * ==============================================================================
    */
    using UnityEngine;
    using System.Collections.Generic;
    using System.Linq;
    
    
    public class Dictionary : MonoBehaviour {
        Dictionary<int, string> list = new Dictionary<int, string>();
    	void Start () {
            //添加元素
            list.Add(1, "1111");
            list.Add(2, "2222");
            list.Add(3, "3333");
            list.Add(4, "4444");
            list.Add(5, "5555");
            //更改值
            list[1] = "qqqq";
    
            // 情形一:不存在才添加
            if (list.ContainsKey(6)==false)
            {
                list.Add(6, "6666");
            }
            // 情形二:不存在添加,存在则替换
            if (list.ContainsKey(2) == false)
            {
                list.Add(2, "wwww");
            }
            else {
                list[2] = "wwww";
            }
            Debug.Log("获得字典的数目: " + list.Count);
            Debug.Log("获得键的数目: "+list.Keys.Count);
            Debug.Log("获得值的数目: " + list.Values.Count);
            //移除所指定的键的值
            list.Remove(3);
    
            foreach (var item in list)
            {
                Debug.Log("Key的值: " + item.Key + "   value的值: " + item.Value);
                //通过值找键
                if (list.ContainsValue("6666"))
                {
                    Debug.Log(item.Key);
                }
                //通过键找值
                if (list.ContainsKey(2))
                {
                    Debug.Log(item.Value);
                }
            }
        }
    }
    

      

  • 相关阅读:
    连接数据库方法
    jdbc加载驱动方法
    MySQL数据库事务隔离级别
    事务和JDBC事务隔离级别
    IO
    java中从键盘输入的三种方法
    Java IO流学习总结八:Commons IO 2.5-IOUtils
    Java IO流学习总结七:Commons IO 2.5-FileUtils
    Java IO流学习总结五:转换流-InputStreamReader、OutputStreamWriter
    Java Code Examples
  • 原文地址:https://www.cnblogs.com/mclll520/p/6796021.html
Copyright © 2011-2022 走看看