Hellow
i created a binary file "Adata.bin" using Class1.cs which has 4
property, each property can set and return a string size of 32 characters
so the size of one record is =sizeof(char) * 4* 32 = 256; sizeof(char)=2;
my goal is to find number of record using the equation
Nrecord=size of file/size of one record
MessageBox.Show(MyRandom.SIZE.ToString());
in code below ,i made N=1,N=2,N=3
remember sizeof(char) in my machine is 2
the followin result were by MessageBox(......
when N=1
size by file lenght =132 but (sizeof(char))*(4 property) * (32 character per one property )=128
when N=2
size by file lenght =264 ...................(8 property)...................................=256
when N=3
size by file lenght =396 ...................(12 property)...................................=384
it seems the machine adds 1 char or byte per one property.why it did not adds sizeof(char) per property ?!
what if used the code in 64 bit machine would the result be same ?
needs explanation please
private void FormLoad(object sender, EventArgs e)
{ int N,i; string ss; long s1;
MessageBox.Show("Class1.SIZE=" + Class1.SIZE.ToString());
ss = "012345678901234567890123456789012";
Tot.BANDNAME = ss; Tot.BANDNO = ss;
Tot.NO = ss; Tot.COST = ss;
fsMainInOut1=new FileStream("Adata.bin",FileMode.Truncate,FileAccess.ReadWrite);
BinaryMainOut1 = new BinaryWriter(fsMainInOut1);
fsMainInOut1.Seek(0 * Class1.SIZE, SeekOrigin.Begin);
N = 3;
for (i = 0; i < N; i++)
{
BinaryMainOut1.Write(Tot.BANDNAME);
BinaryMainOut1.Write(Tot.BANDNO);
BinaryMainOut1.Write(Tot.NO);
BinaryMainOut1.Write(Tot.COST);
}
BinaryMainOut1.Close(); fsMainInOut1.Close();
FileInfo f = new FileInfo(FileName);
s1 = f.Length;
MessageBox.Show("size by file lenght =" + s1.ToString());
}