title: c# - Binary Search Algorithm for Custom Class String List
body: <p>Basically I need help adapting my Binary Search Algorithm to work with my string list as seen below. <strong>Note</strong>, I have to use a written Binary Search algorithm, no use of built-in c# functions like .BinarySearch .</p>
  
  <p>I will now show you how the list is formatted and the list itself:</p>
  
  <pre><code>// This class formats the list, might be useful to know
  
  public class Demo
  {
      public string Col;
      public string S1;
      public string S2;
      public string S3;
  
      public override string ToString()
      {
          return string.Format("Col: {0}, S1: {1}, S2: {2}, S3: {3}", Col, S1, S2, S3);
      }
  }
  
  // The list itself
  
  var list = new List&lt;Demo&gt;
          {   
              new Demo {Col = "Blue", S1 ="88", S2 ="Yes"},
              new Demo {Col = "Green", S1 ="43", S2 ="Yes"},
              new Demo {Col = "Red", S1 ="216", S2 ="No"},
              new Demo {Col = "Yellow", S1 ="100", S2 ="No"}
          };
  </code></pre>
  
  <p>The list is already sorted into alphabetical order of the 'Col' string values, hence why Blue is first and Yellow is last. The 'Col' is the part of the list that needs to be searched. Below I have inserted my current Binary Search that can search int arrays.</p>
  
  <pre><code>public static int BinarySearch_R(int key, int[] array, int low, int high)
      {
          if (low &gt; high) return -1;
          int mid = (low + high) / 2;
          if (key == array[mid])
          {
  
              return mid;
          }
          if (key &lt; array[mid]) {
              return BinarySearch_R(key, array, low, mid - 1);
          } else {
              return BinarySearch_R(key, array, mid + 1, high);
          }
      }
  </code></pre>
  
  <p>I need help adapting my BinarySearch Algorith to work for the list above. If you guys have any questions, or need to see more of my code, just ask. </p>