A Built-in Function to Convert from String to Byte

c#

Solution

System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
byte[] bytes= encoding.GetBytes(stringData);

Problem

I have the following function: ``` public static byte[] StringToByte(string str) { int length = str.Length; byte[] ba = new byte[length]; for (int i = 0; i < length; i++) { ba[i] = (byte)str[i]; } return ba; } ``` I wonder whether there is a built-in function for this method?

Original source