/*
#########
############
#############
## ###########
### ###### #####
### ####### ####
### ########## ####
#### ########### ####
#### ########### #####
##### ### ######## #####
##### ### ######## ######
###### ### ########### ######
###### #### ############## ######
####### ##################### ######
####### ###################### ######
####### ###### ################# ######
####### ###### ###### ######### ######
####### ## ###### ###### ######
####### ###### ##### #####
###### ##### ##### ####
##### #### ##### ###
##### ### ### #
### ### ###
## ### ###
__________#_______####_______####______________ 身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
我们的未来没有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);
}
}
}
}

  

C# 字典常用方法的更多相关文章

  1. python中列表和字典常用方法和函数

    Python列表函数&方法 Python包含以下函数: 序号 函数 1 cmp(list1, list2)比较两个列表的元素 2 len(list)列表元素个数 3 max(list)返回列表 ...

  2. python 字符串 列表 字典 常用方法

    今天学习内容如下: 1.学习昨天练习题目的解题新方法 #1.使用while循环输入 1 2 3 4 5 6 8 9 10 ''' count = 0 while count < 10: coun ...

  3. Python 全栈开发:dict(字典)常用方法操作、dict嵌套

    数据类型的划分:可变数据类型和不可变数据类型. 不可变数据类型(可哈希):元祖.bool.int.str 可变数据类型(不可哈希):list.dict,set(集合) dict(字典): dict(字 ...

  4. dict字典常用方法总结,数据解构(解包)

    dict {'name':'holle'}字典存储大量关联型数据,可迭代的,最多只有200个键.查询数据速度非常快,符合二分查找(有100个数比如找75会先找到50然后判断,所以2^7次方7次即可找到 ...

  5. python 基础 1.5 python数据类型(四)--字典常用方法示例

    一. 字典 #字典 dict1 = {'name':'lzc','age':'20','sex':'man'} print dict1 print type(dict1) >>> { ...

  6. python字典常用方法

    字典(Dictionary) 字典是一个无序.可变和有索引的集合.在 Python 中,字典用花括号编写,拥有键和值. 实例 创建并打印字典: thisdict = { "brand&quo ...

  7. [BS-02] iOS数组、字典、NSNumber 新写法—— @[]、@{}

    IOS数组.字典.NSNumber 新写法—— @[].@{}   //标准写法 NSNumber * number = [NSNumber numberWithInt:]; NSArray * ar ...

  8. python基础之元组(Tuple)、字典(Dictionary)详解

    元组定义 元组是另一个数据类型,类似于List(列表). 元组用”()”标识.内部元素用逗号隔开.但是元素不能二次赋值,相当于只读列表. 举例: tuple = ( ‘abcd’, 786 , 2.2 ...

  9. iOS 数组字典操作

    iOS开发中需要大量对dictionary和array进行操作,因此我们需要一种更加安全可靠的操作方法来避免不必要的crash.当然可以通过自定义dictionary 和array重载增删改查的方法来 ...

随机推荐

  1. Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.

    from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...

  2. QT获取窗口句柄

    winId()函数 SendMessage((HWND)(this->dlg->winId()),WM_SEND_MY_MESSAGE,0,0);

  3. 强化学习--QLearning

    1.概述: QLearning基于值函数的方法,不同与policy gradient的方法,Qlearning是预测值函数,通过值函数来选择 值函数最大的action,而policy gradient ...

  4. mybatis oracle -批量插入,存在则更新

    <insert id="batchUpdatePBWUserInfo" parameterType="java.util.List"> MERGE ...

  5. 从零开始学习cocoStudio(1)--cocoStudio是什么?

    一.cocoStudio是什么? CocoStudio是一套专业的永久免费的游戏开发工具集,帮助开发者快速创建游戏资源,将大部分繁琐的游戏开发工作使用编辑器来快速制作,CocoStudio包含了游戏开 ...

  6. quick-cocos2d-x 游戏开发之一】开发工具sublime text及其强力插件QuickXDev

    http://blog.csdn.net/yihaiyiren/article/details/17220927

  7. 虚拟机连不上网 Xshell连不上虚拟机

    以centos7 为例 1,确定network connection 为NAT 2, 打开网络连接中心 Control Panel\Network and Internet\Network Conne ...

  8. A stock

    1. 密集成交不太妙 主力抛压退为好

  9. C# 选项卡控件

    选项卡控件,它提供一系列操作按钮,单击不同的按钮可以在各个页面之间进行切换. 在Windows Form应用程序中,选项卡控件即“TebPage”控件,它公开“TebPage”属性,表示一个由“Tab ...

  10. 102.自己实现ArrayList

    package collection; import java.util.ArrayList; import java.util.List; /** * 自己实现一个ArrayList,帮助理解底层结 ...