I welcome everyone, I made a method, it reads a file in parts, we input a stream, returns a variable number of blocks method, and also returns a KeyValuePair structure. I can’t figure out how to exit the method correctly using return. Thank you in advance.
public static KeyValuePair<int, byte[]> Read_Blok(Stream stream,out int count_blok) { int size = 1024 * 1024; int count_part = (int) (stream.Length /size );// количество частей int sizeLastPart = count_part - 1; // размер последней части byte[] buffer = new byte[size]; // размер буффера count_blok = 0; int count; for (int i = 0; i < count_part; i++) { if (i == count_part - 1) // когда достигаем последней части, последняя часть блока может быть меньше чем заданный буфер { buffer = new byte[sizeLastPart]; count=stream.Read(buffer, 0, buffer.Length); count_blok = count_blok + 1; return new KeyValuePair<int, byte[]>(count_blok,buffer); } else { count = stream.Read(buffer, 0, buffer.Length); count_blok = count_blok + 1; return new KeyValuePair<int, byte[]>(count_blok,buffer); stream.Position = i * buffer.Length;// сдвигаем позицию в потоке } } }