title: C++, Net, WindowsForms Sorting list by values of other list
body: <p>I have two lists. One has type of MyClass and is filled with these classes wrote by me. And the second one has some int values.</p>
  
  <p>And the problem is that I don't know how to deal with sorting the first list using values of the second one.
  I have no idea how to write an IComparer to use sort list method. I saw an example in msdn but I don't know how to change it.
  <a href="http://msdn.microsoft.com/en-us/library/234b841s.aspx#Y535" rel="nofollow">http://msdn.microsoft.com/en-us/library/234b841s.aspx#Y535</a></p>
  
  <p>Here's my program:</p>
  
  <p>//##################################</p>
  
  <pre><code>ref class MyClass{
  private:
    int x;
    int y;
    String^ name;
  public:
    MyClass(int x, int y, String^ name){
    this-&gt;x = x;
    this-&gt;y = y;
    this-&gt;name = name;
  }
  ...
  };
  
  //###### in some button which will initialize...:
  
  List&lt;MyClass^&gt;^ listMyClass = gcnew List&lt;MyClass^&gt;(3);
  listMyClass-&gt;Add(gcnew MyClass(3, 5, "class1"));
  listMyClass-&gt;Add(gcnew MyClass(1, 2, "class2"));
  listMyClass-&gt;Add(gcnew MyClass(6, 8, "class3"));
  
  List&lt;int&gt;^ numbers = gcnew List&lt;int&gt;(3);
  numbers-&gt;Add(2);
  numbers-&gt;Add(4);
  numbers-&gt;Add(1);
  </code></pre>
  
  <p>//###################################</p>
  
  <p>These numbers of numbers List represent some kind of a status of elements of listMyClass. So I'd like to sort listMyClass using values form the list numbers.
  I would like to have such result after sorting:
  <code>listMyClass[1]</code> is first because number 4 from the list numbers is the highest. Then
  <code>listMyClass[0]</code> and then <code>listMyClass[2]</code></p>
  
  <p>Are there any posibilities to deal with this challange?</p>