Binary.Write in C#

My impression was that I could use Binary.Write for data other than byte arrays by giving the variable as a single argument of BinaryWrite. But when I do it with a short integer, it gets padded with two null bytes. I don't want this, since what I am generating is a sound file. Is there a way to do this

Answer this question

Binary.Write in C#

  • T2k

    Dear Matthew, thank you for your help. With your encouragement I went back to the code and realized my assumption that "int" meant a 16-bit integer, as it did in the old Turbo-C that I used to use. Since "int" now means a 32-bit integer, the program wrote four bytes, of which the last two were either 00 00 or FF FF. I have now repaired it by changing the specification from "int" to "short". Thanks again.
  • renaud.besnard

    Great! :)
  • moria yizhaki

    Do you mean "BinaryWriter.Write(...)"

    That should only write two bytes if you pass it a 16 bit integer.

    Can you post some sample code that doesn't work


  • Binary.Write in C#