Read File in C#
<p>I found a C# source code that read from file which have 1000000 double number. The source code is below.</p>

<pre><code>public void filereader()
{           
    using (BinaryReader b = new BinaryReader(File.Open("C:\\Users\\Hanieh\\Desktop\\nums.txt", FileMode.Open)))
    {
        int length = (int)b.BaseStream.Length;
        byte[] fileBytes = b.ReadBytes(length);

        for (int ii = 0; ii &lt; fileBytes.Length - 32 ; ii++)
        {
            savg1[ii / 2] = (double)(BitConverter.ToInt16(fileBytes, ii) / 20000.0);// inja error index midee
            ii++;
        }
    }
}
</code></pre>

<p>when I run source code to read from text file I have an error that related to savg1 index that is out of bound. I debug step by step and result shows size of length= 24000000 but savg1=1000000. my question is here: how this source code work and how I can fix this problem. </p>