title: How can I extract a subset of a dictionary into another one in C#?
body: <p>I want to filter out some dictionary pairs I do not need for further processing. Check this sample code out:</p>
  
  <pre><code>static void Main(string[] args)
  {
      var source = new Dictionary&lt;string, dynamic&gt;();
  
      source.Add("number", 1);
      source.Add("string1", "One");
      source.Add("string2", "Two");
      source.Add("string3", "Three");
  
      var onlyStrings = source.Where(s =&gt; s.Key != "number").ToDictionary(s =&gt; s.Key);
  }
  </code></pre>
  
  <p>In this case, onlyStrings is a <code>Dictionary&lt;string, KeyValuePair&lt;string, object&gt;&gt;</code></p>
  
  <p>but I want onlyStrings to have the following pairs (a subset of the source dictionary):</p>
  
  <ul>
  <li>Key: "string1", Value: "One"</li>
  <li>Key: "string2", Value: "Two"</li>
  <li>Key: "string3", Value: "Three"  </li>
  </ul>
  
  <p>What is the best way to get such result?</p>