相关疑难解决方法(0)

C# 将字符串复制到字节缓冲区

我正在尝试将 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);
}
Run Code Online (Sandbox Code Playgroud)

c# arrays string

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrays ×1

c# ×1

string ×1