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);
}
}
}
}
C# 字典常用方法的更多相关文章
- python中列表和字典常用方法和函数
Python列表函数&方法 Python包含以下函数: 序号 函数 1 cmp(list1, list2)比较两个列表的元素 2 len(list)列表元素个数 3 max(list)返回列表 ...
- python 字符串 列表 字典 常用方法
今天学习内容如下: 1.学习昨天练习题目的解题新方法 #1.使用while循环输入 1 2 3 4 5 6 8 9 10 ''' count = 0 while count < 10: coun ...
- Python 全栈开发:dict(字典)常用方法操作、dict嵌套
数据类型的划分:可变数据类型和不可变数据类型. 不可变数据类型(可哈希):元祖.bool.int.str 可变数据类型(不可哈希):list.dict,set(集合) dict(字典): dict(字 ...
- dict字典常用方法总结,数据解构(解包)
dict {'name':'holle'}字典存储大量关联型数据,可迭代的,最多只有200个键.查询数据速度非常快,符合二分查找(有100个数比如找75会先找到50然后判断,所以2^7次方7次即可找到 ...
- python 基础 1.5 python数据类型(四)--字典常用方法示例
一. 字典 #字典 dict1 = {'name':'lzc','age':'20','sex':'man'} print dict1 print type(dict1) >>> { ...
- python字典常用方法
字典(Dictionary) 字典是一个无序.可变和有索引的集合.在 Python 中,字典用花括号编写,拥有键和值. 实例 创建并打印字典: thisdict = { "brand&quo ...
- [BS-02] iOS数组、字典、NSNumber 新写法—— @[]、@{}
IOS数组.字典.NSNumber 新写法—— @[].@{} //标准写法 NSNumber * number = [NSNumber numberWithInt:]; NSArray * ar ...
- python基础之元组(Tuple)、字典(Dictionary)详解
元组定义 元组是另一个数据类型,类似于List(列表). 元组用”()”标识.内部元素用逗号隔开.但是元素不能二次赋值,相当于只读列表. 举例: tuple = ( ‘abcd’, 786 , 2.2 ...
- iOS 数组字典操作
iOS开发中需要大量对dictionary和array进行操作,因此我们需要一种更加安全可靠的操作方法来避免不必要的crash.当然可以通过自定义dictionary 和array重载增删改查的方法来 ...
随机推荐
- Spark Streaming 002 统计单词的例子
1.准备 事先在hdfs上创建两个目录: 保存上传数据的目录:hdfs://alamps:9000/library/SparkStreaming/data checkpoint的目录:hdfs://a ...
- net npoi将List<实体>导出excel的最简单方法
只是临时导数据用的.方便.最基本的方法, [HttpGet] [Route("ExportEnterprise")] public BaseResponse ExportEnter ...
- STL(标准模板库)基本概念
一.什么是STL STL(Standard Template Library,标准模板库)的从广义上讲分为三类:algorithm(算法).container(容器)和iterator(迭代器),容器 ...
- GCD(Swift)
1.取消过去的接口 说起 GCD, 大家肯定回想起类似 dispatch_async 这样的语法. GCD 的这个语法模式无论是和 Objc 还是 Swift 的整体风格都不太打掉. 所以 Swift ...
- C++笔试题2(基础题)
温馨提醒:此文续<C++笔试题(基础题)> (112)请写出下列程序的输出内容 代码如下: #include <iostream> using namespace std; c ...
- 电脑已连接wifi的密码查询
有时候,想登陆自己家的无线网络(尤其朋友来家里突然要连接无线网络),脑子刹那间一片空白想不起来密码,怎么办呢? 其实,我们可以通过电脑来查看网络的密码,现在分享如何在笔记本电脑上查看连接过的无线网络密 ...
- array_contains 分析函数使用演示
Hive中的array_contains函数与SQL中的 in关键字 操作类似,用于判定 包含(array_contains)或不包含(!array_contains)关系.与 in不同的是array ...
- tensorflow学习4-过拟合-over-fitting
过拟合: 真实的应用中,并不是让模型尽量模拟训练数据的行为,而是希望训练数据对未知做出判断. 模型过于复杂后,模型会积极每一个噪声的部分,而不是学习数据中的通用 趋势.当一个模型的参数比训练数据还要多 ...
- C# Http文件上传下载
C# Http文件下载公共类(支持断点续传) http://www.cnblogs.com/hayden/archive/2012/04/26/2472815.html C# Http方式下载文件到本 ...
- Redis内存分析方法
一般会采用 bgsave 生成 dump.rdb 文件,再结合 redis-rdb-tools 和 sqlite 来进行静态分析. BGSAVE:在后台异步(Asynchronously)保存当前数据 ...