Using a c# program BinaryWriter class I am writing 2 words in a file
bw.write(i);
bw.write(s);
where i
is an integer with value 25736483
. and s
is a string with value I am happy
I am reading the file again and outputting the value to a textbox.text
iN = br.ReadInt32();
newS = br.ReadString();
this.textBox1.Text = i.ToString() + newS;
The integer will be stored in 4 bytes and the string in another 11 bytes. When we read the ReadInt32 how did the system know that it has to spawn 4 bytes and not only 1 byte. Why did the system read all the 4 bytes and displayed the value correctly as 25736483
?