StringBuilder.MaxCapacity StringBuilder.MaxCapacity StringBuilder.MaxCapacity StringBuilder.MaxCapacity Property


取得這個執行個體的最大容量。Gets the maximum capacity of this instance.

 property int MaxCapacity { int get(); };
public int MaxCapacity { get; }
member this.MaxCapacity : int
Public ReadOnly Property MaxCapacity As Integer


這個執行個體可以容納的最大字元數。The maximum number of characters this instance can hold.


此執行的最大容量為Int32.MaxValueThe maximum capacity for this implementation is Int32.MaxValue. 不過,這個值是執行特有的,在其他或更新版本中可能會不同。However, this value is implementation-specific and might be different in other or later implementations. 您可以藉由StringBuilder StringBuilder(Int32, Int32)呼叫函式來明確設定物件的最大容量。You can explicitly set the maximum capacity of a StringBuilder object by calling the StringBuilder(Int32, Int32) constructor.

在 .net Core 和 .NET Framework 4.0 和更新版本中,當您藉由呼叫StringBuilderStringBuilder(Int32, Int32)函式來具現化物件時, StringBuilder實例的長度和容量都可以成長超過其MaxCapacity的值property.In .NET Core and in the .NET Framework 4.0 and later versions, when you instantiate the StringBuilder object by calling the StringBuilder(Int32, Int32) constructor, both the length and the capacity of the StringBuilder instance can grow beyond the value of its MaxCapacity property. 當您呼叫Append(String)AppendFormat(String, Object)方法來附加小型字串時,可能會發生這種情況。This can occur particularly when you call the Append(String) and AppendFormat(String, Object) methods to append small strings.