dictionary

33.YAML 配置文件语言

烈酒焚心 提交于 2020-09-30 14:49:51
概述 YAML 是专门用来写配置文件的语言,非常简洁和强大,远比 JSON 格式方便。YAML 语言的设计目标,就是方便人类读写。它实质上是一种通用的数据串行化格式。它的基本语法规则如下: 大小写敏感 使用缩进表示层级关系 缩进时不允许使用 TAB 键,只允许使用空格。 缩进的空格数目不重要,只要相同层级的元素左侧对齐即可 # 表示注释,从这个字符一直到行尾,都会被解析器忽略。YAML 支持的数据结构有三种: 对象: 键值对的集合,又称为映射(mapping)/ 哈希(hashes) / 字典(dictionary) 数组: 一组按次序排列的值,又称为序列(sequence) / 列表(list) 纯量(scalars): 单个的、不可再分的值 YAML 对象 对象的一组键值对,使用冒号结构表示 animal: pets YAML 数组 一组连词线开头的行,构成一个数组 - Cat - Dog - Goldfish 数据结构的子成员是一个数组,则可以在该项下面缩进一个空格 - Array - Cat - Dog - Goldfish YAML 复合结构 对象和数组可以结合使用,形成复合结构 languages: - Ruby - Perl - Python websites: YAML: yaml.org Ruby: ruby-lang.org Python: python.org

C#字典Dictionay多线程读是否是安全的

只愿长相守 提交于 2020-09-30 07:32:56
答案:是线程安全的,只读不写多线程下,完全不需要加锁! 测试代码: using System; using System.Diagnostics; using System.Threading; using System.Collections.Generic; namespace hello { public class ThreadSafe { Dictionary < int , int > dits = new Dictionary< int , int > (); public ThreadSafe() { for ( int i = 0 ; i < 100 ; i++ ) { dits.Add(i, i); } } public void Test( object i) { int t = Convert.ToInt32(i); int v; Thread.Sleep( 1 ); dits.TryGetValue(t, out v); if (! t.Equals(v)) { Console.WriteLine( " i:{0},v:{1} " , t, v); } } } } 模拟5万个线程读字典,看看是否混乱: static void Main( string [] args) { ThreadSafe ts = new ThreadSafe(); Random