title: C# sorting part of an array based on another array
body: <p>I have an array of a class that is representing a user and another array of a class that is representing pinned items (currently only user ids). Here are the classes:</p>
  <pre><code>public class User
  {
      public int UserId { get; set; }
      public bool Pinned { get; set; }
  
      public User(int userId, bool pinned)
      {
          UserId = userId;
          Pinned = pinned;
      }
  }
  
  public class PinnedItem
  {
      public int UserId { get; set; }
  
      public PinnedItem(int userId)
      {
          UserId = userId;
      }
  }
  </code></pre>
  <p>All user ids of pinned users are saved in a specific order (order of pinned items) and I want to order the array of users so that pinned users are on top and those pinned users follow the order of pinned items array. So for example, if I have an array of users like:</p>
  <p><code>var users = new []{ new User(1, true), new User(2, false), new User(3, true) }</code></p>
  <p>and a pinned items array that looks like this:</p>
  <p><code>var pinnedItems = new [] { new PinnedItem(3), new PinnedItem(1) }</code></p>
  <p>then I want the resulting array to look like this:</p>
  <p><code>[ {3, true}, {1, true}, {2, false} ]</code></p>
  <p>I also need it to work if the array of pinned items isn't in any kind of order. So if I have this array of users:</p>
  <p><code>var users = new []{ new User(1, false), new User(2, true), new User(3, true), new User(4, true) }</code></p>
  <p>and this array of pinned items:</p>
  <p><code>var pinnedItems = new [] { new PinnedItem(3), new PinnedItem(2), new PinnedItem(4) }</code></p>
  <p>in this case I want the resulting array to look like this:</p>
  <p><code>[ {3, true}, {2, true}, {4, true}, {1, false} ]</code></p>
  <p>Any kind of help will be very much appreciated. Also if there is anything unclear in the question, I am sorry and will edit it accordingly if need be.</p>