关于hash的一些用法

java 代码
  1. users_hash = {"tom" => "password0",      
  2. "adi" => "password1",      
  3. "aaron" => "password2" }      
  4.      
  5. # The following line will not add anything to users_hash.      
  6. # But will return a hash that has users_hash and      
  7. # the new added entry.      
  8. users_hash.merge({"sam1" => "password3"})      
  9.      
  10. #The following line will modify users_hash by      
  11. #adding the new entry and return it      
  12. users_hash.merge!({"sam2" => "password3"})      
  13. # or you can make it like this      
  14. #users_hash.merge!("sam2" => "password3")      
  15.      
  16. users_hash.each {  |key, value|      
  17. puts "Key is #{key} and value is #{value}"     
  18. }      
  19. cities = [   
  20. {"Name" => "los angeles""State" => "CA"},   
  21. {"Name" => "las vegas""State" => "NV"},   
  22. {"Name" => "miami""State" => "FL"}   
  23. ]   
  24.   
  25. cities.map! { |c| c.merge!("Count" => 1) }   
  26.   
  27. puts cities   

你可能感兴趣的:(C++,c,C#)