问题:
How do I convert a string
to a byte[]
in .NET (C#) without manually specifying a specific encoding? 在不手动指定特定编码的情况下,如何在.NET(C#)中将string
转换为byte[]
?
I'm going to encrypt the string. 我将对字符串进行加密。 I can encrypt it without converting, but I'd still like to know why encoding comes to play here. 我可以加密而不进行转换,但是我仍然想知道为什么编码在这里起作用。
Also, why should encoding be taken into consideration? 另外,为什么还要考虑编码? Can't I simply get what bytes the string has been stored in? 我不能简单地获取字符串存储在哪个字节中? Why is there a dependency on character encodings? 为什么要依赖字符编码?
解决方案:
参考一: https://stackoom.com/question/1z1W/如何在不手动指定编码的情况下在C-中获得字符串的一致字节表示形式参考二: https://oldbug.net/q/1z1W/How-do-I-get-a-consistent-byte-representation-of-strings-in-C-without-manually-specifying-an-encoding
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4298420