title: C# Convert IDictionary to two ILists
body: <p>I need to create an IList with the keys and another IList with the values, taken from an IDictionary. How do I do it? I had to avoid generics (List&lt;> and Dictionary&lt;>) because the types inside them are user defined types not known at compile time.</p>
  
  <p>I have a method that processes a DataTable and return a dictionary. The type of the dictionary keys are defined at runtime:</p>
  
  <pre><code>DataTable myDataTable = ....
  Type dictionaryKeysType=Type.GetType("myType");
  IDictionary myDictionary = ProcessDataTable (myDataTable, dictionaryKeysType);
  IList keys= (IList)myDictionary.Keys;
  IList values= (IList)myDictionary.Values;
  </code></pre>
  
  <p>How do I do it? I had to avoid generics (List&lt;> and Dictionary&lt;>) because the types inside them are user defined types not known at compile time. So, althought the method returns a 'Dictionary&lt;>', I cant declare:</p>
  
  <pre><code>Dictionary&lt;dictionaryKeysType, int&gt; myDictionary = ProcessDataTable (myDataTable, dictionaryKeysType)
  </code></pre>
  
  <p>so I must receive it as a 'IDictionary'. Using 'var' is not a solution, as as the problem would come later when trying to cast it to 'Dictionary'</p>
  
  <p>My code compiles but raises an exception when converting to IList. For example, if "myType" is "uint", I get: (Can't convert an object of type 'KeyCollection[System.UInt32,System.Int32]' to type 'System.Collections.IList').</p>
  
  <p>Please, help :(</p>