日期:2014-05-18 浏览次数:20861 次
class Program { private static readonly StringBuilder outPutMessage = new StringBuilder(); private static readonly string outPutString = string.Empty; static void Main() { //不关心的内容 } private static void AppendtoMessage(string message) { outPutMessage.Append("\n" + message); outPutString = outPutString + "\n" + message; } }
using System; namespace Test { class Program { private readonly static MyString _MyString = new MyString(); static void Main() { // 下面这行是错误的 // _MyString = new MyString(); _MyString.Append("1"); _MyString.Append("2"); _MyString.Append("3"); Console.WriteLine(_MyString.Value); Console.ReadKey(); } } class MyString { private String _value; public String Value { get { return _value; } } public MyString() { _value = String.Empty; } public void Append(String s) { _value = String.Format("{0}{1}", _value, s); } } }