当前位置: 代码迷 >> ASP.NET >> StringWriter 和StringBuilder 什么关系?该怎么解决
  详细解决方案

StringWriter 和StringBuilder 什么关系?该怎么解决

热度:3125   发布时间:2013-02-25 00:00:00.0
StringWriter 和StringBuilder 什么关系?
StringWriter 和StringBuilder 什么关系?
看了msdn依然的不明白

------解决方案--------------------------------------------------------
using System;
using System.IO;
using System.Text;
 
class StrWriter
{
static void Main()
{
StringBuilder strBuilder = 
new StringBuilder("file path characters are: ");
StringWriter strWriter = new StringWriter(strBuilder);
 
strWriter.Write(
Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
 
strWriter.Close();
 
// Since the StringWriter is closed, an exception will 
// be thrown if the Write method is called. However, 
// the StringBuilder can still manipulate the string.
strBuilder.Insert(0, "Invalid ");
Console.WriteLine(strWriter.ToString());
}
}

------解决方案--------------------------------------------------------
stringwriter用来操作stringbuilder
好比 streamwriter 和 stream
  相关解决方案