什么是的StreamWriter和的BinaryWriter之间的区别?

编程入门 行业动态 更新时间:2024-10-28 14:32:45
本文介绍了什么是的StreamWriter和的BinaryWriter之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这真的混淆了我,说我要一个整数保存到一个文件中,INT X = 56,的BinaryWriter采用ASCII等效56表示在内存 00000000 00000000 00000000 00111000,具体做法是:空空空8,并将其写入文件?我对么?有人可以解释如何将这些twofunction当我应该使用每个人?即时通讯使用C#顺便说一句。 thanx提前!

this really confuses me, say i want to save an integer into a file, int x=56, the binarywriter takes the ascii equivalent of the representation of 56 in memory 00000000 00000000 00000000 00111000 , which would be : null null null 8 and write it to the file? am i correct? can someone explain how those twofunction and when should i use each of them? im using c# btw. thanx in advance!

推荐答案

从MSDN页面的的StreamWriter 和的BinaryWriter 你可以清楚地看到差异:

From the MSDN pages for StreamWriter and BinaryWriter you can clearly see the differences:

StreamWriter的:

StreamWriter:

实现为在一个特定的编码写入字符流的的TextWriter

Implements a TextWriter for writing characters to a stream in a particular encoding.

的BinaryWriter:

BinaryWriter:

在二至流写入基本类型和支持写入A特定的编码字符串。

Writes primitive types in binary to a stream and supports writing strings in a specific encoding.

第一个写东西的文本,二进制第二写入,小尾数,所以 INT X = 56 将被写入 00111000 00000000 00000000 00000000 。

The first one writes things as text, the second writes in binary, little endian, so int x = 56 would be written 00111000 00000000 00000000 00000000.

更多推荐

什么是的StreamWriter和的BinaryWriter之间的区别?

本文发布于:2023-05-25 00:28:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/218696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   StreamWriter   BinaryWriter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!