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 及更高版本StringBuilder中, 当通过StringBuilder(Int32, Int32)调用构造函数实例化对象时, 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.