如何减少或改进代码?
private readonly StringBuilder _buffer = new StringBuilder();
public void WriteD(int i) {
_buffer.Append(Encoding.UTF8.GetString(BitConverter.GetBytes(i)));
}
我需要写入一些数据类型(int、ushort、string 等)的字符串二进制数据。转换“stringToHex”后字符串应如下所示(输入int 13和10):0D 00 00 00 0A 00 00 00
谢谢!