title: How to extract values from arrays using upper and lower limits?
body: <p>Given two arrays, I need to extract values from arrayB based on where the range(actual values) falls in arrayA.</p>
  
  <pre><code>Index     0    1  2    3  4    5  6   7   8     9  10   11  12
  -------------------------------------------------------------
  ArrayA = {0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4,  4.5,  5, 5.5,  6}
  ArrayB = {1, 0.2, 3,   4, 5,   6,5.5,  8,  9,11.1, 11,  12,  3}
  </code></pre>
  
  <p>Given the following ranges, I need to extract the following results</p>
  
  <pre><code>RangeToExtract*  IndexInArrayA  Expected Values To Extract
  --------------  -------------  --------------------------
  0 -&gt; 1          [0,2]          1,0.2,3
  1 -&gt; 3          [3,6]          4,5,6,5.5
  3 -&gt; 5          [7,10]         5.5,8,9,11.1,11
  1 -&gt; 5          [3,10]         4,5,6,5.5,8,9,11.1,11
  3 -&gt; 10         [7,12]         8,9,11.1,11,12,3 
  
  * Refers to the actual values in ArrayA
  </code></pre>
  
  <p>Note: Given the RangeToExtract <code>(0-&gt;1</code>), determine the indexes in ArrayA where these values are, the result being <code>(0-&gt;1)</code> maps to <code>[0,2]</code> (The value 1 is in position 2 in ArrayA)</p>
  
  <p>I only figured that the following special cases exists (not sure if there are more)</p>
  
  <ol>
  <li>the lower limit is equal to zero and    </li>
  <li>when the upper limit does not exist in ArrayA</li>
  </ol>
  
  <p>Further info:</p>
  
  <ul>
  <li>Both arrays will be the same size</li>
  <li>ArrayA will always be sorted</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>private double[] GetRange(double lower, double upper)
  { 
      var myList = new double[ArrayA.Length];
      var lowerIndex = Array.IndexOf(ArrayA, lower);
      var upperIndex = Array.IndexOf(ArrayA, upper);
  
      // special case 1
      if (lowerIndex != 0)
      {
          lowerIndex = lowerIndex + 1; 
      }
  
      // special case 2
      if (upperIndex == -1)
      {
          upperIndex = ArrayA.Length-1; 
      }
  
      for (int i = lowerIndex; i &lt;= upperIndex; i++)
      {
          myList[i] = ArrayB[i];
      }
      return myList;
  }
  </code></pre>
  
  <p>Given the above code, have all the special cases been taken into account? Is there a better way to write the above code?</p>