This design pattern converts an array of bytes to an ASCII string.
// required for ASCIIEncoding class
using System.Text;
private ScriptHelper helper = new ScriptHelper();
public void SendBytes()
{
// prepare a byte array
byte[] bytes = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x2E };
ProcessBytes( bytes );
}
private void ProcessBytes( byte[] bytes )
{
// convert the byte array to a string using ASCII encoding
string text = System.Text.Encoding.ASCII.GetString( bytes, 0, bytes.Length );
// display the string
helper.Logger.Debug( text );
}
This design pattern:
creates a byte array with 12 elements, calls a method passing the array,
the ProcessBytes method converts the array of bytes to a string using the ASCIIEncoding class,
displays the converted string.