Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>List&lt;List&lt;string&gt;&gt;</code> is really your best bet in this case. But I agree, it's kludgy. Personally, I would create a custom class that implements a two-dimensional indexer and maybe use a <code>List&lt;List&lt;T&gt;&gt;</code> internally. </p> <p>For example:</p> <pre><code>public class DynamicTwoDimensonalArray&lt;T&gt; { private List&lt;List&lt;T&gt;&gt; Items = new List&lt;List&lt;T&gt;&gt;(); public T this[int i1, int i2] { get { return Items[i1][i2]; } set { Items[i1][i2] = value; } } } </code></pre> <p>This is a basic idea to get you going; clearly the setter needs to deal with bounds issues. But it's a start. </p> <p><strong>Edit:</strong> </p> <blockquote> <p><em>No. As I said, I would prefer to index them by string. And they may not always be sequential (might have a missing number in the middle).</em> - <strong>Mystere Man</strong></p> </blockquote> <p>Hmm... this is interesting. If that's the case, your best bet would be to create some sort of concatenation of the combination of the two indexers and use that as the key in a single-level dictionary. I would still use a custom class to make using the indexing easier. For example:</p> <pre><code>public class TwoDimensionalDictionary { private Dictionary&lt;string, string&gt; Items = new Dictionary&lt;string, string&gt;(); public string this[string i1, string i2] { get { // insert null checks here return Items[BuildKey(i1, i2)]; } set { Items[BuildKey(i1, i2)] = value; } } public string BuildKey(string i1, string i2) { return "I1: " + i1 + " I2: " + i2; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload