Skip to content

HostToNetworkOrder with a value of type Single

Dale

Asked Aug 2, 2006, 7:26 AM EDT1 answer
Share
LinkedInX
i need to take a value from a textbox, convert the string to Single, put it into HostToNetworkOrder, and insert it into a byte array.

here is the code without the HostToNetworkOrder conversion:

blTempArray = BitConverter.GetBytes(Convert.ToSingle(txtNomThick.Text));


Whenever i put in the IPaddress.HostToNetworkOrder() method it says it has some invalid arguments. It only accepts values of type Long, Short, and Int.  How can i get around this problem?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Nevermind i got it, i had to cast the value as a long and then convert it:

    Code
    byte[] blTempArray = new byte[4];
    Single slTextBox = Convert.ToSingle(spTextBox);
    Int32 ilTextBox = (Int32) slTextBox;
    ilTextBox = System.Net.IPAddress.HostToNetworkOrder(ilTextBox);
    blTempArray = BitConverter.GetBytes(ilTextBox);
    0