StringBuilder.MaxCapacity 屬性

定義

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

public:
 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(Int32, Int32) 的「函數」,明確設定 StringBuilder 物件的最大容量。You can explicitly set the maximum capacity of a StringBuilder object by calling the StringBuilder(Int32, Int32) constructor.

在 .NET Core 和 .NET Framework 4.0 和更新版本中,當您藉由呼叫 StringBuilder(Int32, Int32) 的函式來具現化 StringBuilder 物件時,StringBuilder 實例的長度和容量都可以成長超過其 MaxCapacity 屬性的值。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.

適用於