c# - Is data “lost” when using binary data in a string?

后端 未结 9 1768
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 13:58

I\'ve tried reading a JPG file using the StreamReader class\' ReadToEnd() method which returns a string.

For some reason though, when I wri

9条回答
  •  失恋的感觉
    2021-01-16 14:36

    String is designed for holding unicode characters; not binary. For binary, use a byte[] or Stream. Or an Image etc for more specialized image handling.

    Despite the name, StreamReader is actually a specialized TextReader - i.e. it is a TextReader that reads from a Stream. Images are not text, so this isn't the right option.

提交回复
热议问题