【发布时间】:2026-02-20 03:05:01
【问题描述】:
有没有静态方法将字符串、int等转换成字节/字节数组?
这个方法我已经知道了:
public static byte[] FromString(string Input)
{
ASCIIEncoding ByteEncoder = new ASCIIEncoding();
return ByteEncoder.GetBytes(Input);
}
但我想知道是否有更好的方法。如果我制作了 ASCII 编码器的静态实例来使用会不会有问题?
另外 - 在性能方面 - 上述 ASCII 转换方法与通过 for 循环或其他多行解决方案的此类方法相比如何?
另外 - 我什么时候应该使用 ASCII 和 Unicode?p>
威廉
【问题讨论】:
-
上面的多个问题应该是各自的问题。
-
你不应该发布多个问题。
-
.NET String to byte Array C# 的可能重复项
标签: c# bytearray byte type-conversion