Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way of achieving a jagged array is a dictionary. Something based on the code below may get you started.</p> <pre><code>Dictionary&lt;string, string&gt;[] array; void MyMethod(int[] ckeys, int gotovalue, string[] command) { int x = 0; for(int ii = (ckeys[0] + 1); ii &lt; gotovalue; ii++) { string no = preg_replace(" .*", "", command[ii]); string temp = preg_replace("^[0-9]*. ", "", command[ii]); string cid = preg_replace(" (.*", "", temp); temp = preg_replace(".* (wait: ", "", command[ii]); string wait = preg_replace(",.*", "", temp); temp = preg_replace(".*, prio: ", "", command[ii]); string prio = preg_replace(").*", "", temp); array[x] = new Dictionary&lt;string, string&gt;(); array[x]["no"] = no; array[x]["cid"] = cid; array[x]["wait"] = wait; array[x]["prio"] = prio; array[x]["debug"] = command[ii]; x++; } } string preg_replace(string aa, string bb, string cc) { return aa + bb + cc; } </code></pre> <p>Edit:</p> <p>I took the code in the initial version of the question and tried to convert it into C#, assuming that all the unspecified types were strings. The called routine <code>preg_replace</code> was not specified, but it appeared to take three strings and return one.</p> <p>The original question has the line <code>$x = 0;</code> which appears to define <code>$x</code> as an integer and initialize it. The line <code>$array[$x] = array();</code> appears to say that <code>$array</code> at the given integer index is made to refer to an empty array. Then the line <code>$array[$x]["no"]</code> sets the <code>"no"</code> element of that array to a string. The C# I proposed declares <code>array</code> as an array of dictionaries. A C# dictionary is a form of associative array, in the Perl language it would be called a 'hash'. The whole piece of code will write values into the structure, effectively initializing it from the values found in the parameters to <code>MyMethod</code>.</p> <p>Elsewhere will need a statement such as <code>array = new Dictionary&lt;string, string&gt;[gotovalue]</code> to make <code>array</code> refer to an actual array.</p>
 

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