title: c# Data memory storage Sizeof, basestream.position and filestream.length are contradictory
body: <pre><code>string file = @&quot;G:\test.dat&quot;;
          int  num = 12;
          char c = 'w';
          FileStream fsSave = new FileStream(file, FileMode.Create);
          BinaryWriter bwSave = new BinaryWriter(fsSave);
          Console.WriteLine(&quot;Start position:&quot; + bwSave.BaseStream.Position);
          //bwSave.Write((int)num);
          bwSave.Write((char)c);
          Console.WriteLine(&quot;End position:&quot; + bwSave.BaseStream.Position);
          bwSave.Flush();
          bwSave.Close();
          fsSave.Close();
          FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
          BinaryReader br = new BinaryReader(fs);
          Console.WriteLine(&quot;char:&quot;+sizeof(char));
          Console.WriteLine(&quot;int:&quot; + sizeof(int));
          Console.WriteLine(&quot;fs.Length:&quot; + fs.Length);
          Console.ReadLine();
          br.Close();
          fs.Close();
  I write a char type data or an int type data to a binary file, and then read them  
   into memory from the binary file to try to explore the number of bytes they store in memory.
  When I write a char type data, the console output is:  
  C#
  Start position:0
  End position:1
  char:2
  int:4
  fs.Length:1
  </code></pre>
  <p>From the start position and end position displayed in [bwsave. Basestream. Position], we can know that a char data occupies 1 byte.
  It can be known from [sizeof (char)] that a char type data occupies 2 bytes.
  From [FS. Length], we can know that a char type data occupies 1 byte.
  How many bytes does a char data occupy?</p>
  <p>When I write only one int type data, the values displayed by [bwsave. Basestream. Position], [sizeof (char)] and [FS. Length] are consistent, and they all occupy 4 bytes.</p>