title: Sorting an image list loaded from resources by name
body: <p>Say you have a <code>List&lt;Image&gt;</code>, you add all the images found in the solution's resources using something like this;</p>
  
  <pre><code>using (ResourceSet resourceSet = SomeProject.Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true))
          {
              foreach (DictionaryEntry entry in resourceSet)
              {
                  SomeList.Add((Image)entry.Value);
              }
          }
  </code></pre>
  
  <p>In this case, there'll be three images in our resources. <code>Apple.png Banana.png, Cactus.png</code></p>
  
  <p>How can I sort this list alphabetically so I can loop through it in the right order, getting <code>Apple -&gt; Banana -&gt; Cactus</code>?</p>
  
  <p>I've read <a href="https://stackoverflow.com/questions/1700240/how-to-sort-resourceset-in-c-sharp">How to sort ResourceSet in C#</a> which I tried to apply to my situation but to no avail.</p>
  
  <p>By myself I've tried assigning <code>entry.Key</code> to the Image's tag and then doing <code>someList.OrderBy(f =&gt; f.Tag).ToList();</code></p>
  
  <p>Here's the full code which I use to test this</p>
  
  <pre><code>    List&lt;Image&gt; someList = new List&lt;Image&gt;();
  
      private void button1_Click(object sender, EventArgs e)
      {
          using (ResourceSet resourceSet = WindowsFormsApplication52.Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true))
          {
              foreach (DictionaryEntry entry in resourceSet)
              {
                  Image i = (Image)entry.Value;
                  i.Tag = entry.Key;
                  someList.Add((Image)i);
              }
  
              someList.OrderBy(f =&gt; f.Tag).ToList();
          }
  
          foreach(var x in someList)
          {
              PictureBox pb = new PictureBox();
              pb.Image = x;
              pb.Size = new System.Drawing.Size(200, 200);
              pb.SizeMode = PictureBoxSizeMode.Zoom;
              flowLayoutPanel1.Controls.Add(pb);
          }
      }
  </code></pre>
  
  <p>This is the result I seem to get every time,
  <img src="https://i.stack.imgur.com/lEvJI.jpg" alt="http://puu.sh/c5BTz/41f828cf1b.jpg"></p>
  
  <p>I don't know if it takes file size into account but in this case the file sizes of the images are also in order. (Apple.png is the largest, cactus is the smallest).</p>
  
  <p>Help is greatly appreciated.</p>