Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# byte转string

作者:自然ㄣ之光   发布日期:2025-08-01   浏览:62

// 将 byte 数组转换为 string 的示例代码

using System;
using System.Text;

class Program
{
    static void Main()
    {
        // 定义一个 byte 数组
        byte[] byteArray = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 };

        // 使用 UTF8 编码将 byte 数组转换为字符串
        string result = Encoding.UTF8.GetString(byteArray);

        // 输出转换后的字符串
        Console.WriteLine(result);  // 输出: Hello World
    }
}

解释说明:

  • byte[] byteArray:定义了一个包含字节数据的数组。每个字节代表一个字符的编码值。
  • Encoding.UTF8.GetString(byteArray):使用 UTF-8 编码将字节数组转换为字符串。UTF-8 是一种常见的字符编码方式,可以表示几乎所有语言的字符。
  • Console.WriteLine(result):输出转换后的字符串。

通过这种方式,你可以轻松地将字节数组转换为可读的字符串。

上一篇:c# newtonsoft.json

下一篇:c# 遍历字典

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#游戏开发

c#网络编程

c# rectangle

c# 取字符串最后一个字符

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站