Dictionary dictionary for C #

Source: Internet
Author: User

Dictionary

Dictionary can replace the Hashtable;
There is a new way to traverse

foreach(KeyValuePair <int,stringin dic){}
Dictionary Practice
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.threading.tasks;namespace Dictionary Dictionary {class Program {Static voidMain (string[] args) {dictionary<int,string> dic =Newdictionary<int,string> (); Dic. ADD (1,"Jing Ke"); Dic. ADD (2,"Niezheng"); Dic. ADD (3,"Exclusive"); Dic. ADD (4,"close to the");foreach(intIteminchDic. Keys) {Console.WriteLine ("{0} corresponding value is {1}", Item,dic[item]); }foreach(keyvaluepair<int,string> PairinchDIC) {Console.WriteLine ("{0} corresponding value is {1}", pair. Key,pair.            Value);        } console.readkey (); }    }}
Detecting character occurrences with dictionary
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.threading.tasks;namespace Dictionary detect letter Occurrences {class Program {Static voidMain (string[] args) {//detect the number of occurrences of each character in the string "Welcome to China";dictionary<Char,int> dic =Newdictionary<Char,int> ();stringstr ="Welcome to China"; for(inti =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<Char,int> IteminchDIC) {Console.WriteLine ("{0} has occurred {1} times", item. Key,item.            Value);        } console.readkey (); }    }}

Dictionary dictionary for C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.