title: Use own IComparer<T> with Linq OrderBy
body: <p>I have a generic</p>
  
  <pre><code>List&lt;MyClass&gt;
  </code></pre>
  
  <p>where <code>MyClass</code> has a property <code>InvoiceNumber</code> which contains values such as:</p>
  
  <p>200906/1<br>
  200906/2<br>
  ..<br>
  200906/10<br>
  200906/11<br>
  200906/12<br></p>
  
  <p>My list is bound to a</p>
  
  <pre><code>BindingList&lt;T&gt;
  </code></pre>
  
  <p>which supports sorting with linq:</p>
  
  <pre><code>protected override void ApplySortCore(
             PropertyDescriptor property, ListSortDirection direction)
  {
  
      _sortProperty = property;
      _sortDirection = direction;
  
      var items = this.Items;
  
      switch (direction)
      {
          case ListSortDirection.Ascending:
              items = items.OrderByDescending(x =&gt; property.GetValue(x)).ToList();
              break;
          case ListSortDirection.Descending:
              items = items.OrderByDescending(x =&gt; property.GetValue(x)).ToList();
              break;
      }
  
      this.Items = items;
  
  }
  </code></pre>
  
  <p>However the default comparer sorts (as supposed) like this:</p>
  
  <p>200906/1<br>
  200906/10<br>
  200906/11<br>
  200906/12<br>
  200906/2<br></p>
  
  <p>which is nasty in this case.</p>
  
  <p>Now I want to use my own <code>IComparer&lt;T&gt;</code> with this. It looks like this:</p>
  
  <pre><code>public class MyComparer : IComparer&lt;Object&gt;
  {
  
      public int Compare(Object stringA, Object stringB)
      {
          String[] valueA = stringA.ToString().Split('/');
          String[] valueB = stringB.ToString().Split('/');
  
          if(valueA .Length != 2 || valueB .Length != 2)
               return String.Compare(stringA.ToString(), stringB.ToString());
  
          if (valueA[0] == valueB[0]) 
          {
            return String.Compare(valueA[1], valueB[1]);
          }
          else
          {
            return String.Compare(valueA[0], valueB[0]);
          }
  
      }
  
  }
  </code></pre>
  
  <p>and changed the <code>ApplySortCore</code> code to use this <code>IComparer</code>:</p>
  
  <pre><code>case ListSortDirection.Ascending:
      MyComparer comparer = new MyComparer();
      items = items.OrderByDescending(
                x =&gt; property.GetValue(x), comparer).ToList();
      break;
  </code></pre>
  
  <p>When I debug my code, I see that <code>MyComparer.Compare(object, object)</code> is called multiple times and returns the right values (-1, 0, 1) for a compare method.</p>
  
  <p>But my list is still sorted the "wrong" way. Am I missing something? I have no clue.</p>