Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not entirely sure of your question.<br /> Are you simply trying to fill an array with lines of a file?<br /> That is simple and this will do it:</p> <pre><code>int[] mArray = File.ReadAllLines("pathAndFilename").Select(x =&gt; int.Parse(x)).ToArray(); </code></pre> <p>Is that sufficient? If not, then please clarify your question a little.</p> <p>Using more info I think you want something more like this:</p> <pre><code> private static int[,] FillArrays(string file, int rightLength) { int[] mArray = File.ReadAllLines(file).Select(x =&gt; int.Parse(x)).ToArray(); int size = mArray.Length / rightLength; if (((mArray.Length ^ rightLength) &gt;= 0) &amp;&amp; (mArray.Length % rightLength != 0)) { size++; } int[,] arrayDos = new int[size, rightLength]; int counter = 0; int arrayNum = 0; foreach (int i in mArray) { arrayDos[arrayNum, counter] = i; counter++; if (counter == rightLength) { counter = 0; arrayNum++; } } return arrayDos; } </code></pre> <p>And call it like this:</p> <pre><code>int[,] mArray = FillArrays(@"Z:\testnums.txt", 4); </code></pre> <p>You can pass in the right side size:</p> <pre><code>{int[8, 2]} [0, 0]: 0 [0, 1]: 1 [0, 2]: 2 [0, 3]: 3 [1, 0]: 0 [1, 1]: 1 [1, 2]: 2 [1, 3]: 3 [2, 0]: 0 [2, 1]: 2 [2, 2]: 2 [2, 3]: 3 [3, 0]: 0 [3, 1]: 1 [3, 2]: 3 [3, 3]: 3 </code></pre> <p>2 will also work with your example data.</p> <pre><code>{int[8, 2]} [0, 0]: 0 [0, 1]: 1 [1, 0]: 2 [1, 1]: 3 [2, 0]: 0 [2, 1]: 1 [3, 0]: 2 [3, 1]: 3 [4, 0]: 0 [4, 1]: 2 [5, 0]: 2 [5, 1]: 3 [6, 0]: 0 [6, 1]: 1 [7, 0]: 3 [7, 1]: 3 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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