简单介绍一下字典的遍历
来源:互联网 发布:淘宝店铺仓库管理 编辑:程序博客网 时间:2024/06/06 14:14
大家可能都知道字典这种数据结构吧!但是对于字典的遍历都清楚吗?
下面就提供几种方法吧!不说多了,直接来代码吧!
using System.Collections;using System.Collections.Generic;using UnityEngine;public class ExampleTest : MonoBehaviour{ //如何遍历一个字典的四种方式 // Use this for initialization void Start() { Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("LY", 1); list.Add("YZY", 2); list.Add("YM", 3); list.Add("YZLY", 4); foreach (var item in list) { Debug.Log(item.Key + item.Value); } //使用KeyValuePair<T,K> foreach (KeyValuePair<string, int> kv in list) { Debug.Log(kv.Key + kv.Value); } //通过键的集合取值 foreach (string key in list.Keys) { Debug.Log(key + list[key]); } //直接取值 foreach (var val in list.Values) { Debug.Log(val); } //for循环 List<string> test = new List<string>(list.Keys); for (int i = 0; i < list.Count; i++) { Debug.Log(test[i] + list[test[i]]); } }}
世界上没有十全十美的东西,这几种遍历方式都各有千秋!大家自己体会吧!
阅读全文
0 0
- 简单介绍一下字典的遍历
- 简单的介绍一下python
- 简单介绍一下SNMP4J
- 简单介绍一下OGraph
- 简单介绍一下AjAx
- 通过程序来简单实践一下HashMap的的遍历
- 简单介绍一下索引 约束 角色一些简单的SQL
- 字典的遍历
- 字典的遍历
- 字典的更新,遍历
- 04-字典的遍历
- 简单介绍一下sap fico入门凭证,有兴趣的可以简单了解一下哦!
- 字典树的简单介绍及其如何求最短前缀
- 字典转换成模型简单的介绍与使用
- python的列表和字典(简单介绍)
- 简单介绍一下这个项目
- 简单介绍一下我自己
- 五、简单 介绍一下 变量
- linux_yum的配置文件-repo文件
- Braintree 常见问题解决
- Topcoder 720 div2-C RainbowGraph
- 声明全局变量的三种方式
- Oracle数据之select * for update恢复小结(1)
- 简单介绍一下字典的遍历
- 2.6删除文件
- Union-Find算法
- Java日期比较
- STM32F429I-DISCO ucLinux 开发环境搭建
- 使用kettle进行不同数据库的数据导入
- C#多线程的基础整理(上)——Thread和ThreadPool
- listView中只显示一行的问题处理
- Ubuntu服务器打开/关闭mysql远程连接