I'm trying to convert a string
to a byte[]
using the ASCIIEncoder
object in the .NET library. The string
will never contain non-ASCII characters, but it will usually have a length greater than 16. My code looks like the following:
public static byte[] Encode(string packet)
{
ASCIIEncoder enc = new ASCIIEncoder();
byte[] byteArray = enc.GetBytes(packet);
return byteArray;
}
By the end of the method, the byte array should be full of packet.Length
number of bytes, but Intellisense tells me that all bytes after byteArray[15]
are literally questions marks that cannot be observed. I used Wireshark to view byteArray
after I sent it and it was received on the other side fine, but the end device did not follow the instructions encoded in byteArray
. I'm wondering if this has anything to do with Intellisense not being able to display all elements in byteArray
, or if my packet is completely wrong.