Advertisement
grubcho

Staff - Dictionaries

Jul 9th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace sorted_dictionar
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var phonebook = new SortedDictionary<string, string>();
  14.             phonebook["Anna"] = "+1-555-8976";
  15.             phonebook["Pesho"] = "+1-555-5030";
  16.             phonebook["Bojidar"] = "+1-555-1234";
  17.             phonebook["Nakov"] = "+359-899-555-592";
  18.             phonebook["Nakov"] = "+359-2-981-9819"; // Replace
  19.  
  20.             Console.WriteLine(phonebook.Count);
  21.             Console.WriteLine(string.Join(", ", phonebook.Keys));
  22.             //Console.WriteLine(string.Join(", ", phonebook.Values));
  23.             //phonebook.Clear();
  24.             //Console.WriteLine(phonebook.Count);
  25.             Console.WriteLine(phonebook.ContainsKey("Pesho"));
  26.             Console.WriteLine(phonebook.ContainsValue("+1-555-8976"));
  27.  
  28.             foreach (string key in phonebook.Keys)
  29.             {
  30.                 Console.WriteLine(key);
  31.             }
  32.             foreach (KeyValuePair<string, string> pair in phonebook)
  33.             {
  34.                 Console.WriteLine("{0} --> {1}", pair.Key, pair.Value);
  35.             }
  36.  
  37.             string value;
  38.             phonebook.TryGetValue("Pesho", out value);
  39.             Console.WriteLine(value);
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement