1
using System
.Collections
.Generic
;
3 namespace IEnumerableExtras
6 /// Provedes extension method for <see cref="IDictionary{T,T}"/> to convert dictionary to an array.
8 public static class DictionaryToArray
11 /// Convert this instance of <see cref="IDictionary{T,T}"/> to a rectangular
12 /// arry of type <typeparamref name="T"/>.
14 /// <typeparam name="T">Type for both keys and values of dictionary.</typeparam>
15 /// <param name="dictionary"></param>
16 /// <returns></returns>
17 public static T
[,] ToArray
< T
>( this IDictionary
<T
, T
> dictionary
)
19 T
[,] result
= new T
[dictionary
.Count
,2];
22 foreach ( KeyValuePair
<T
, T
> pair
in dictionary
)
24 result
[ i
, 0 ] = pair
.Key
;
25 result
[ i
, 1 ] = pair
.Value
;