C # Dictionary

Source: Internet
Author: User

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 ();}}}
    
   
  

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.