Mercurial > repos > IBBoard
comparison Collections/DictionaryUtils.cs @ 28:41ddcd61dc92
Add method to get array of keys from dictionary
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 09 Apr 2009 15:10:51 +0000 |
parents | 0352fa33ee8f |
children | e38192f55d2d |
comparison
equal
deleted
inserted
replaced
27:4ea1fc351533 | 28:41ddcd61dc92 |
---|---|
33 dictionary.Values.CopyTo(col, 0); | 33 dictionary.Values.CopyTo(col, 0); |
34 } | 34 } |
35 | 35 |
36 return col; | 36 return col; |
37 } | 37 } |
38 | |
39 /// <summary> | |
40 /// Takes the set of keys in a dictionary and returns them as an array of typed objects. | |
41 /// </summary> | |
42 /// <param name="dictionary"> | |
43 /// A <see cref="IDictionary"/> to extract an array of keys from | |
44 /// </param> | |
45 /// <returns> | |
46 /// An array of <see cref="KEY_TYPE"/> objects taken from the Keys property of the dictionary, or NULL if the dictionary is NULL | |
47 /// </returns> | |
48 public static KEY_TYPE[] ToKeyArray<KEY_TYPE, VALUE_TYPE>(IDictionary<KEY_TYPE, VALUE_TYPE> dictionary) | |
49 { | |
50 if (dictionary == null) | |
51 { | |
52 return null; | |
53 } | |
54 | |
55 int entryCount = dictionary.Count; | |
56 KEY_TYPE[] col = new KEY_TYPE[entryCount]; | |
57 | |
58 if (entryCount > 0) | |
59 { | |
60 dictionary.Keys.CopyTo(col, 0); | |
61 } | |
62 | |
63 return col; | |
64 } | |
38 | 65 |
39 /// <summary> | 66 /// <summary> |
40 /// Takes two dictionaries and merges them. If a key exists in both dictionaries then the value in <code>firstDictionary</code> takes priority. | 67 /// Takes two dictionaries and merges them. If a key exists in both dictionaries then the value in <code>firstDictionary</code> takes priority. |
41 /// </summary> | 68 /// </summary> |
42 /// <param name="firstDictionary"> | 69 /// <param name="firstDictionary"> |