Byte[] mtime = new Byte[4];
mtime = BitConverter.GetBytes(root.LastWriteTime.ToBinary());
fs.Write(mtime, 0, mtime.Length);
When Save That Binary File. It(LastWriteTime) occupies 8Bytes. I want 'LastWriteTime' only use 4Bytes. What should I do? Is there a way?
sorry, I'm Bad English....
You cannot shrink the representation of a DateTime object without losing information (i.e. precision). If you are okay with losing information, you merely need to decide which information is most important to you. As this answer shows, you can truncate information from the underlying data type (a long), and just take the information you need.
If you need millisecond precision only, why not lose the least significant bits
int timeStamp = (int)(DateTime.Now.Ticks >> 10) // lose smallest 10 bits