c# error for index was outside the bounds of array
        Posted  
        
            by 
                iliailiaey
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by iliailiaey
        
        
        
        Published on 2013-11-01T09:32:08Z
        Indexed on 
            2013/11/01
            9:54 UTC
        
        
        Read the original article
        Hit count: 341
        
arrays
i have written below code but i have the error:Index was outside the bounds of the array.i cant understand its reason.how can i correct the code for preventing the error?(in the code,i want to make an array byte of size 57600 from an array byte of size 38400)
            int q = 0;
            int nbytes = 57600;
            byte[] gh = new byte[38400];
            byte[] byte8 = new byte[nbytes];
            byte[] aa = { 0xf8, 0x07, 0XE0, 0X1F };
            for (int y = 0; y < nbytes-3; y += 3)
            {
                if (q < 38400-3)
                {                
          byte8[y] = (byte)(gh[q] & aa[1]);
          byte8[y + 1] = (byte)(((gh[q] & aa[1]) << 5) | ((gh[q + 1] & aa[2]) >> 3));
          byte8[y + 2] = (byte)((gh[q + 1] & aa[3]) << 3);
                    q += 2; 
                }
            }
© Stack Overflow or respective owner