StringWriter的或StringBuilder的StringWriter、StringBuilder

由网友(此人丶卟①般)分享简介:有什么区别,当我应该使用一个或其他?What is the difference and when should I use one or the other?推荐答案StringWriter从TextWriter,这使得各种类,而无需关心到哪里去写入文本。在的StringWriter 的情况下,输出只是到内存中。...

有什么区别,当我应该使用一个或其他?

What is the difference and when should I use one or the other?

推荐答案

StringWriter从TextWriter,这使得各种类,而无需关心到哪里去写入文本。在的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.

StringBuilder本质上是一个缓冲,让您无需创建一个新的字符串对象,每一次执行多个操作(通常附加)为逻辑串。你可以使用这个来构建一个字符串中的多个操作。

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.

阅读全文

相关推荐

最新文章