Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Dictionary<string, int> dicTest = new Dictionary<string, int>();
  2. dicTest.Add("kluc", 0);
  3. dicTest.Add("k1", 1);
  4. dicTest.Add("k2", 2);
  5. dicTest.Add("k3", 3);
  6. dicTest.Add("k4", 4);
  7.  
  8. //get value based on key
  9. int value;
  10. dicTest.TryGetValue("kluc", out value);
  11.  
  12. //get list of all keys, values or pairs within dictionary using linq
  13. List<string> keys = dicTest.Select(x => x.Key).ToList();
  14. List<int> values = dicTest.Select(x => x.Value).ToList();
  15. List<Tuple<string, int>> listInsteadOfDic = dicTest.Select(x => new Tuple<string, int>(x.Key, x.Value)).ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement