如何在不手动指定编码的情况下在C#中获得字符串的一致字节表示形式?

ε祈祈猫儿з 提交于 2020-07-29 11:32:30

问题:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!