title: Get closest/next match in .NET Hashtable (or other structure)
body: <p>I have a scenario at work where we have several different tables of data in a format similar to the following:</p>
  
  <pre><code>Table Name: HingeArms
  Hght   Part #1       Part #2
  33     S-HG-088-00   S-HG-089-00
  41     S-HG-084-00   S-HG-085-00
  49     S-HG-033-00   S-HG-036-00
  57     S-HG-034-00   S-HG-037-00
  </code></pre>
  
  <p>Where the first column (and possibly more) contains numeric data sorted ascending and represents a range to determine the proper record of data to get (e.g. height &lt;= 33 then Part 1 = S-HG-088-00, height &lt;= 41 then Part 1 = S-HG-084-00, etc.)</p>
  
  <p>I need to lookup and select the nearest match given a specified value.  For example, given a height = 34.25, I need to get second record in the set above:</p>
  
  <pre><code>41     S-HG-084-00   S-HG-085-00
  </code></pre>
  
  <p>These tables are currently stored in a VB.NET Hashtable "cache" of data loaded from a CSV file, where the key for the Hashtable is a composite of the table name and one or more columns from the table that represent the "key" for the record.  For example, for the above table, the Hashtable Add for the first record would be:</p>
  
  <pre><code>ht.Add("HingeArms,33","S-HG-088-00,S-HG-089-00")
  </code></pre>
  
  <p>This seems less than optimal and I have some flexibility to change the structure if necessary (the cache contains data from other tables where direct lookup is possible... these "range" tables just got dumped in because it was "easy").  I was looking for a "Next" method on a Hashtable/Dictionary to give me the closest matching record in the range, but that's obviously not available on the stock classes in VB.NET.</p>
  
  <p>Any ideas on a way to do what I'm looking for with a Hashtable or in a different structure?  It needs to be performant as the lookup will get called often in different sections of code.  Any thoughts would be greatly appreciated.  Thanks.</p>