How to get surrounding information from a cell in a table
<h2>Background</h2>

<p>I'm looking for hints / pointers on how to approach this.  When I search for table or grid, I get the UI stuff which is not what I'm looking for.</p>

<p>I don't know if this sounds like homework, but it is not.  This is for a map of crops and I need to determine the crops planted around a particular plot of land.</p>

<h2>Problem</h2>

<p>I have a table of information, its 6 rows by 6 columns, but <strong>it can be any size</strong>.</p>

<p>I need to find a box in that table, and then get the information from all of the boxes around it.</p>

<pre><code>|-1-|-2-|-3-|-4-|-5-|-6-|
|-7-|-8-|-9-|-A-|-B-|-C-|
|-D-|-E-|-F-|-G-|-H-|-I-|
|-J-|-K-|-L-|-M-|-N-|-O-|
|-P-|-Q-|-R-|-S-|-T-|-U-|
|-V-|-W-|-X-|-Y-|-Z-|-0-|
</code></pre>

<p>So I need to be able to pick box M and get the information for F,G,H,N,T,S,R,L</p>

<p><em>Note, if box J was needed, it is okay to return blanks or nulls for the boxes on the left that doen't exist.  It does not wrap around and get the boxes from the other side of the table.</em></p>

<h2>My Idea</h2>

<p>I guess I could start with an array of arrays.</p>

<pre><code>private static string[][] tableData;
</code></pre>

<p>So when looking for box M, I would need to get the row (i) and column (j) index for M, then the surrounding cells are as "simple" as:</p>

<pre><code>| i-1, j-1 | i-1, j | i-1, j+1 |
| i, j-1   | i, j   | i, j+1   |
| i+1, j-1 | i+1, j | i+1, j+1 |
</code></pre>

<p>And when asked for box M, I could find box M's index, then get the prior "row" and then index -1, index, and index + 1.  Do that for M's row -1, M's row and then M's row + 1.</p>

<p>Is that a fair and good way of doing this or are there better, perhaps already built classes that I should use?</p>

<p><strong>So the question: is an array of arrays the best way to handle this problem, or is there a better way?</strong></p>
