title: c# dictionaries intersect
body: <p>I have a question about Linq / Lambda and the following issue:</p>
  
  <p>I have two dictionaries, primary and secondary... These two dictionaries are defined as Key=string, Value=int. I need to trim down the primary dictionary if the KEYS intersect with secondary dictionary.</p>
  
  <p>i.e.:</p>
  
  <pre><code>primaryDict = ["thing1", 33] ["thing2", 24] ["thing3", 21] ["thing4", 17] ["thing5", 12]
  
  secondaryDict = ["thing1", 22] ["thing3", 20] ["thing4", 19] ["thing7", 17] ["thing9", 10]
  
  resultDict = ["thing1", 33] ["thing3", 21] ["thing4", 17]
  </code></pre>
  
  <p>My attempt:</p>
  
  <pre><code>resultDict = primaryDict.Keys.Intersect(secondaryDict.Keys).ToDictionary(t =&gt; t.Key, t.Value);
  </code></pre>
  
  <p>This obviously does not work because the primaryDict.Keys.Intersect is returning a list of keys... how would I reestablish a new dictionary, or pair down the primary dictionary? Any help would be appreciated.</p>