C# 连接字节 [] 并获取字符串结果



我遇到了一个要求,其中我有来自数据库system.byte[]值。 现在我需要从该bye[]值中获取字符串值。我正在使用datarow迭代datatable值。 有很多列具有system.byte[]值。如何检查system.byte[]值并将其转换为字符串显示结果?

你在这里问两个问题:"如何连接"和"如何转换"。

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
public class Program
{
    public static void Main()
    {
        byte[] bytes1 = { 97, 98, 99, 100 };
        byte[] bytes2 = { 49, 50, 51, 52 };
        // concat
        byte[] bytes = bytes1.Concat(bytes2).ToArray();
        // convert
        string bytesAsString = Encoding.UTF8.GetString(bytes);
        Console.WriteLine(bytesAsString);
    }
}

演示点网小提琴

最新更新