我将尝试将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);
}