title: How do I merge two dictionaries in C#
body: <p>Consider the following situation... </p>
  
  <ul>
  <li>A user belongs to one or more groups</li>
  <li>Group has one or many permissions</li>
  <li>Permission is defined as id and a vector of booleans (for read, write, etc). The vector is about a dozen predefined elements</li>
  </ul>
  
  <p>I need to get an aggregate list of user permissions. In pseudocode, I get all permissions from first group that the user belongs to; and then for subsequent groups, I add new permissions, but for existing ones I need to OR all permissions in the vector. That is, if one group has permissions to read, and another has permissions to write - the user will have the permission to read <strong>and</strong> write.</p>
  
  <p>The operation is not very frequent; so performance is not a big concern.</p>
  
  <p>I am thinking of a Dictionary for the permission vector (C# equivalent of associative array. Theoretically, I can represent it in a normal array, but it feels too error-prone). Say,</p>
  
  <pre><code>var permVector = new Dictionary&lt;string, bool&gt; {
      {"read", true}, {"delete", false} ...
  }
  </code></pre>
  
  <p>Then permissions for a group is another Dictionary</p>
  
  <pre><code>var groupPermissions = new Dictionary&lt;int, Dictionary&lt;string, bool&gt;&gt; {
     { 1, permVector }...
  }
  </code></pre>
  
  <p>(This comes from the database; I am showing this way here just for clarity)</p>
  
  <p>And finally, user permissions would be an intelligent merge of all group permissions. And this is where I feel I am going down the rabbit hole. </p>
  
  <p>Are there any types that are better suited for this task?</p>