C # Dictionary
Dictionary
Dictionary can replace Hashtable;
There is a new Traversal method
foreach(KeyValuePair
kv in dic){}
Dictionary exercises
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace Dictionary {class Program {static void Main (string [] args) {Dictionary
Dic = new Dictionary
(); Dic. add (1, "Jing"); dic. add (2, "zhengzheng"); dic. add (3, ""); dic. add (4, "to leave"); foreach (int item in dic. keys) {Console. writeLine ("{0} corresponds to {1}", item, dic [item]);} foreach (KeyValuePair
Pair in dic) {Console. writeLine ("{0} corresponds to {1}", pair. key, pair. value);} Console. readKey ();}}}
Times of occurrence of characters detected by Dictionary
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace Dictionary Check letter appearance count {class Program {static void Main (string [] args) {// check the number of times each character appears in the string "Welcome To China"; Dictionary
Dic = new Dictionary
(); String str = "Welcome To China"; for (int I = 0; I <str. length; I ++) {if (str [I] = '') {continue;} if (dic. containsKey (str. toLower () [I]) {dic [(str. toLower () [I] ++;} else {dic [(str. toLower () [I] = 1 ;}} foreach (KeyValuePair
Item in dic) {Console. WriteLine ("{0} appears {1} Times", item. Key, item. Value) ;}console. ReadKey ();}}}