title: C# List of objects binary search with a comparer
body: <p>I have an object named Artist.</p>
  
  <pre><code>public class Artist
  {
      public string artistID { get; set; }
      public string artistName { get; set; }
  
      public Artist(string artistID, string artistName)
      {
          this.artistID = artistID;
          this.artistName = artistName;
  
      }
  
      public Artist()
      {
      }
      public Artist(string artistID)
      {
          this.artistID = artistID;
      }
  </code></pre>
  
  <p>Which has a custom Comparer like this:</p>
  
  <pre><code>public class CompareArtists : IComparer&lt;Artist&gt;
  {
  
    public int Compare(Artist x, Artist y)
    {
        if (x.artistID == null) return -1;
        if (y.artistID == null) return 1;
  
      return String.Compare(x.artistID, y.artistID);
     }
  
  }
  </code></pre>
  
  <p>I am trying to see whether an artist is contained in my list of artists in the main program. And I am doing that like this: </p>
  
  <pre><code>Artist tempArtist = new Artist(user[1]);
  Artist result = new Artist();
  
  position = artists.BinarySearch(tempArtist, dc);
  result = artists.ElementAt(position);
                         users.ElementAt(counter).favoriteArtists.Add(result,Int32.Parse(user[2]));
  </code></pre>
  
  <p>The result of the binarysearch, is a negative number which from what I read on MSDN, is the complement of the next largest index. And it is shown when no results were found. However, I am 100% certain that the item I am searching for in my artists list does actually exist there. 
  When I use a linear method, e.g. artists.Single or artists.Find, I get a result. </p>
  
  <p>Do you see anything wrong with my comparer or the way I use binary search?</p>
  
  <p>ps: dc is my comparer: CompareArtists dc = new CompareArtists();
  and user[] is an array of strings that were split from a line I read with stream reader. it cotains the artist ID at [1]
  thanks in advance</p>