1-Dimensional Array Counting Same Elements
<p>I have a 1-dimensional array that fills up a table of 40 random elements (all the values are either 0 or 1).  I want to find the longest consecutive span of values.</p>

<p>For example:</p>

<p>In <code>111100101</code> the longest row would be <code>1111</code> because it has four consecutive values of <code>1</code>.</p>

<p>In <code>011100</code> the result is <code>111</code>.</p>

<p>I have no idea how to check upon the "next element" and check if it's a 0 or 1. 
Like the first would be 1111 (count 4) but the next would be a 0 value, meaning I have to stop counting.</p>

<p>My idea was placing this value (4) in a other array (example: 111100101), and place the value of the 1's back on zero.  And start the process all over again.</p>

<p>To find the largest value I have made another method that checks up the biggest value in the array that keeps track of the count of 0's 1's, this is not the problem.</p>

<p>But I cannot find a way to fill the array tabelLdr up, having all the values of the group of elements of the same kind (being 0 or 1).</p>

<p>In the code below I have 2 if's and of course it will never go into the second if (to check if the next value in the array is != to its current state (being 0 or 1).</p>

<pre><code>public void BerekenDeelrij(byte[] tabel, byte[] tabelLdr) 
{
    byte LdrNul = 0, Ldréén = 0;
    //byte teller = 0;

    for (byte i = 0; i &lt; tabel.Length; i++) 
    {
        if (tabel[i] == 0) 
        {
            LdrNul++;
            //this 2nd if cleary does not work, but i have no idea how to implend this sort of idea in my program.
            if (tabel[i] == 1) //if value != 0 then the total value gets put in the second array tabelLdr, 
            {
                tabelLdr[i] = LdrNul;
                LdrNul = 0
            }
        }

        if (tabel[i] == 1)
        {
            Ldréén++;
            if (tabel[i] == 0)
            {
                tabelLdr[i] = Ldréén;
                Ldréén = 0;
            }
        }

    }/*for*/
}
</code></pre>
