title: Convert object to KeyValuePair
body: <p>I have an <code>IEnumerable&lt;Entityclass&gt;</code> for an entity that has a <code>string</code> and an <code>int</code> member. <strong>i need to convert it to an array of <code>KeyValuePair&lt;string, double&gt;</code> and vice versa.</strong></p>
  
  <p>It fails with a cast error.</p>
  
  <pre><code>[DataContract]
  public class Entityclass
  {
      [DataMember]
      public string text{ get; set; }
      [DataMember]
      public int textcount{ get; set; }
   }
  </code></pre>
  
  <p>I have <code>IEnumerable&lt;Entityclass&gt;</code></p>
  
  <ul>
  <li><p>How do I convert from <code>IEnumerable&lt;Entityclass&gt;</code> to an array of <code>KeyvaluePair&lt;string,
  double&gt;[]</code>?</p></li>
  <li><p>How do I convert the <code>KeyvaluePair&lt;string, double&gt;[]</code> array to a <code>KeyvaluePair&lt;string, int&gt;[]</code> array ?</p></li>
  <li><p>How do I convert <code>KeyvaluePair&lt;string, double&gt;</code> back to an IEnumerable?</p></li>
  </ul>
  
  <p>I have tried:</p>
  
  <ul>
  <li><code>topics is IEnumerable&lt;Entityclass&gt;;</code></li>
  <li><code>topics.Cast&lt;KeyValuePair&lt;string, double&gt;&gt;().ToArray();</code>  Fails with cast error</li>
  </ul>