问题描述
有什么区别,当我应该使用一个或其他?
What is the difference and when should I use one or the other?
推荐答案
<$c$c>StringWriter$c$c>从<$c$c>TextWriter$c$c>,这使得各种类,而无需关心到哪里去写入文本。在的StringWriter
的情况下,输出只是到内存中。你会使用这个,如果你调用它需要一个API一个的TextWriter
,但你只是想建立的结果在内存中。
StringWriter
derives from TextWriter
, which allows various classes to write text without caring where it's going. In the case of StringWriter
, the output is just into memory. You would use this if you're calling an API which needs a TextWriter
but you only want to build up results in memory.
<$c$c>StringBuilder$c$c>本质上是一个缓冲,让您无需创建一个新的字符串对象,每一次执行多个操作(通常附加)为逻辑串。你可以使用这个来构建一个字符串中的多个操作。
StringBuilder
is essentially a buffer which allows you to perform multiple operations (typically appends) to a "logical string" without creating a new string object each time. You would use this to construct a string in multiple operations.
这篇关于StringWriter的或StringBuilder的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!