我正在尝试将 Ascii 字符串复制到字节数组,但无法。如何?
这是我到目前为止尝试过的两件事。两者都不起作用:
public int GetString (ref byte[] buffer, int buflen)
{
string mystring = "hello world";
// I have tried this:
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
buffer = encoding.GetBytes(mystring);
// and tried this:
System.Buffer.BlockCopy(mystring.ToCharArray(), 0, buffer, 0, buflen);
return (buflen);
}