program.cs

来自「csharp课本的源代码」· CS 代码 · 共 29 行

CS
29
字号
using System;
using System.Text;
using System.Collections.Generic;
namespace StringBuilderExample
{
    class Program
    {
        public static void Main()
        {
            StringBuilder str = new StringBuilder();
            Console.WriteLine("字符串是:“{0}”,长度:{1}", str, str.Length);
            Console.WriteLine("内存容量分配:{0}", str.Capacity);
            str = new StringBuilder("test string.");
            Console.WriteLine("字符串是:“{0}”,长度:{1}", str, str.Length);
            Console.WriteLine("内存容量分配:{0}", str.Capacity);
            str.Append("append another string.");
            Console.WriteLine("字符串是:“{0}”,长度:{1}", str, str.Length);
            Console.WriteLine("内存容量分配:{0}", str.Capacity);
            str = new StringBuilder("test string.", 5);
            Console.WriteLine("字符串是:“{0}”,长度:{1}", str, str.Length);
            Console.WriteLine("内存容量分配:{0}", str.Capacity);
            str = new StringBuilder("test string.", 40);
            Console.WriteLine("字符串是:“{0}”,长度:{1}", str, str.Length);
            Console.WriteLine("内存容量分配:{0}", str.Capacity);
            Console.ReadLine();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?