StringBuilder做函数参数
StringBuilder做函数参数:
static void Main(string[] args) { StringBuilder sb = new StringBuilder(); Hello(sb);//StringBuilder做为方法参数使用时不需要赋值,其使用相当于 out str Console.WriteLine(sb.ToString()); string str; World(out str); Console.WriteLine(str); Console.ReadKey(); } public static void Hello(StringBuilder sb) { sb.Append("StringBuilder Hello World"); } public static void World(out string str) { str = "string Hello World"; }
输出结果: