1

when i print path[i,50] to console, the path gets printed. but when i try to read from that path to a stream ( FileStream stream = File.OpenRead(path[i,50]) i get index out of bound on the above line

            string [,] path = new string [10,100];
            byte[][] fileBytes = new byte[10][]; 
            for (int i = 1; i <= 10; i++)
            {
                //defining path
                path[i, 50] = @"C:\Users\t-chkum\Desktop\InputFiles\1MB\" + i + ".txt";

               // Console.WriteLine(path[i,50]);
                    // readind data/* 
                FileStream stream = File.OpenRead(path[i,50]);
                fileBytes[i] = new byte[stream.Length];
                stream.Read(fileBytes[i], 0, fileBytes[i].Length);
                stream.Close();
            }

will be grateful for any help :)

kchahat20
  • 97
  • 1
  • 11
  • 3
    in C#, arrays are 0 indexed.. meaning, they start with a 0. If you create an array with 10 elements, max you can access is [9].. not [10]. change your for loop to i < 10 .. not i <= 10 and start with i = 0; – Jawad Jun 03 '20 at 17:38
  • 1
    Related to what @Jawad said, you should also start your loop at `int i = 0` so you don't skip the first element in the array. – Cameron Bielstein Jun 03 '20 at 17:42

0 Answers0