title: Best way to convert a Java Map to a Dictionary in C#
body: <p>I need to write a function in C# that takes in a java.util.Map and converts it to a C# Dictionary.  (The project I'm working on uses <a href="http://www.ikvm.net/" rel="nofollow">IKVM</a> to use some Java classes in C#.)</p>
  
  <p>I've tried using a foreach loop (e.g. <code>foreach (java.util.Map.Entry in map)</code> or <code>foreach (string key in map.keySet())</code> to add to the Dictionary element-by-element, but it seems that Java Maps and Sets are not enumerable.</p>
  
  <p>What's my best approach here?  Should I use a java.util.Iterator?  (I'm not opposed to using a Java Iterator on principle, but it feels like there should be a cleaner, more "c-sharp-y" way.)  I guess I could get the keySet, use the Set method toArray(), and iterate through <em>that</em>, but again, it doesn't feel "c-sharp-y".  Should I just get over myself and do one of those things, or is there a better way?  (Or, of those two options, which is more efficient in terms of time/space taken?)</p>
  
  <p>For reference, here's a sketch of what I'm trying to do:</p>
  
  <pre><code>public Dictionary&lt;string, object&gt; convertMap(java.util.Map map)
  {
      Dictionary&lt;string, object&gt; dict = new Dictionary&lt;string, object&gt;();
      foreach (String key in map.keySet()) // doesn't work; map is not enumerable
          dict.Add(key, map.get(key));
      return dict;
  }
  </code></pre>