using System;
using System.Text;
class Program
{
static void Main()
{
// 定义一个字符串
string str = "Hello, World!";
// 使用 UTF-8 编码将字符串转换为字节数组
byte[] bytes = Encoding.UTF8.GetBytes(str);
// 输出字节数组的内容
Console.WriteLine("Byte array contents:");
foreach (byte b in bytes)
{
Console.Write(b + " ");
}
}
}
str
,内容是 "Hello, World!"
。Encoding.UTF8.GetBytes
方法将字符串转换为字节数组。这里使用的是 UTF-8 编码,这是一种常见的字符编码方式。如果你需要使用其他编码方式(例如 ASCII 或 Unicode),可以替换 Encoding.UTF8
为 Encoding.ASCII
或 Encoding.Unicode
。
上一篇:internal c#
下一篇:c# post json
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站