title: Sort a dictionary by a custom order
body: <p>This refers to </p>
  
  <p><a href="https://stackoverflow.com/questions/47293353/sort-a-list-by-a-custom-order">Sort a list by a custom order</a></p>
  
  <p>I will go for a similar example... I have a dictionary containing users</p>
  
  <pre><code>public class UserInfo
  {
      public string Name { get; set; }
  
      public string Location { get; set; }
  }
  </code></pre>
  
  <p>the data:</p>
  
  <pre><code>private Dictionary&lt;string, UserInfo&gt; users = new Dictionary&lt;string, UserInfo&gt;(); // id + user
  </code></pre>
  
  <p>and a list of possible locations</p>
  
  <pre><code>        private string[] locations = {
              "europe",
              "america",
              "asia",
              "africa"
          };
  </code></pre>
  
  <p>how can I order this dictionary by these locations?</p>
  
  <p>There should be the output</p>
  
  <blockquote>
    <p>// ... all europeans</p>
    
    <p>// ... all americans</p>
    
    <p>// ... all asians</p>
    
    <p>// ... all africans</p>
  </blockquote>
  
  <p>when calling</p>
  
  <pre><code>    Dictionary&lt;string, UserInfo&gt; sortedUsers = ; // Sorting the dict "users" by locations
  
      foreach (KeyValuePair&lt;string, UserInfo&gt; info in sortedUsers)
      {
          Console.WriteLine("L: " + info.Value.Location + " N: " + info.Value.Name);
      }
  </code></pre>