ValueStringBuilder Struct
- Obsolete: Types with embedded references are not supported in this version of your compiler.
[Obsolete("Types with embedded references are not supported in this version of your compiler.", true)]
public ref struct ValueStringBuilderNo documentation is available.
Nested types
| Name | Description |
|---|---|
| ValueStringBuilder.AppendInterpolatedStringHandler |
Constructors
| Name | Description |
|---|---|
| ValueStringBuilder(int) | Initializes a builder backed by a buffer of at least initialCapacity characters rented from ArrayPool<T>. |
| ValueStringBuilder(Span<char>) | Initializes a builder that writes into initialBuffer and only rents from ArrayPool<T> once the content outgrows it. |
ValueStringBuilder overloads
ValueStringBuilder(int)
ValueStringBuilder.csInitializes a builder backed by a buffer of at least initialCapacity characters rented from ArrayPool<T>.
public ValueStringBuilder(int initialCapacity)Parameters
initialCapacityint- The minimum number of characters the buffer must hold.
ValueStringBuilder(Span<char>)
ValueStringBuilder.csInitializes a builder that writes into initialBuffer and only rents from ArrayPool<T> once the content outgrows it.
Parameters
initialBufferSpan<char>- The buffer to write into, typically stack-allocated.
Properties
| Name | Description |
|---|---|
| Capacity | Gets the number of characters the current buffer can hold before it has to grow. |
| Length | Gets or sets the number of characters written so far. Setting it truncates the content, or exposes characters already present in the buffer when it is increased. |
| RawChars | Gets the whole buffer, including the part past ValueStringBuilder.Length. |
Capacity
ValueStringBuilder.csLength
ValueStringBuilder.csRawChars
ValueStringBuilder.csGets the whole buffer, including the part past ValueStringBuilder.Length.
Property value
Remarks
Everything beyond ValueStringBuilder.Length is uninitialized pooled memory and may hold data left by a previous user of the array. Use ValueStringBuilder.AsSpan to read only what was written.
Indexers
| Name | Description |
|---|---|
| this[int] | Gets a reference to the character at index, which can be used to overwrite it. |
this[int]
ValueStringBuilder.csGets a reference to the character at index, which can be used to overwrite it.
Parameters
indexint- The position of the character, which must be less than
ValueStringBuilder.Length.
Property value
Methods
| Name | Description |
|---|---|
| Append(ValueStringBuilder.AppendInterpolatedStringHandler) | |
| Append(char) | Appends a single character. |
| Append(char, int) | Appends c count times. |
| Append(IFormatProvider?, ValueStringBuilder.AppendInterpolatedStringHandler) | |
| Append(ReadOnlySpan<char>) | Appends the characters of value. |
| Append(string?) | Appends a string. A null string is ignored. |
| Append(Rune) | Appends a Unicode scalar value, encoded as one character or as a surrogate pair. |
| AppendSpan(int) | Reserves length characters at the end of the content and returns them so the caller can write into the buffer directly. ValueStringBuilder.Length is advanced immediately, so the reserved characters are part of the content whether or not they are written to. |
| AppendSpanFormattable<T>(T, string?, IFormatProvider?) | Appends value by formatting it straight into the buffer, falling back to IFormattable.ToString when it does not fit. |
| AsSpan() | Returns the characters written so far, without disposing the builder. |
| AsSpan(int) | Returns the characters written so far from start onwards. |
| AsSpan(int, int) | Returns length characters starting at start. |
| Clear() | Resets ValueStringBuilder.Length to 0, keeping the current buffer. The characters are not erased and stay readable through ValueStringBuilder.RawChars. |
| Dispose() | Releases the buffer back to ArrayPool<T> and resets the builder. Calling it more than once is safe. |
| EnsureCapacity(int) | Grows the buffer so that it can hold at least capacity characters. |
| GetPinnableReference() | Returns a reference to the first character of the buffer, so the builder can be used with a fixed statement. The result is not null-terminated unless ValueStringBuilder.NullTerminate was called. |
| Insert(int, char, int) | Inserts value count times at index. |
| Insert(int, string?) | Inserts s at index. A null string is ignored. |
| NullTerminate() | Writes a null character after the content, growing the buffer if needed, without changing ValueStringBuilder.Length. |
| ToString() | Returns the characters written so far and disposes this instance, returning the rented buffer to the pool. |
Append overloads
Append(ValueStringBuilder.AppendInterpolatedStringHandler)
ValueStringBuilder.AppendInterpolatedStringHandler.cspublic void Append(ref ValueStringBuilder.AppendInterpolatedStringHandler handler)Parameters
No documentation is available.
Append(char)
ValueStringBuilder.csAppend(char, int)
ValueStringBuilder.csAppend(IFormatProvider?, ValueStringBuilder.AppendInterpolatedStringHandler)
ValueStringBuilder.AppendInterpolatedStringHandler.cspublic void Append(IFormatProvider? provider, ref ValueStringBuilder.AppendInterpolatedStringHandler handler)Parameters
providerIFormatProvider?handlerValueStringBuilder.AppendInterpolatedStringHandler
No documentation is available.
Append(ReadOnlySpan<char>)
ValueStringBuilder.csAppends the characters of value.
public void Append(ReadOnlySpan<char> value)Parameters
valueReadOnlySpan<char>- The characters to append.
Append(string?)
ValueStringBuilder.csAppend(Rune)
ValueStringBuilder.Rune.csAppendSpan(int)
ValueStringBuilder.csReserves length characters at the end of the content and returns them so the caller can write into the buffer directly. ValueStringBuilder.Length is advanced immediately, so the reserved characters are part of the content whether or not they are written to.
AppendSpanFormattable<T>(T, string?, IFormatProvider?)
ValueStringBuilder.AppendSpanFormattable.csAppends value by formatting it straight into the buffer, falling back to IFormattable.ToString when it does not fit.
public void AppendSpanFormattable<T>(T value, string? format = null, IFormatProvider? provider = null) where T : ISpanFormattableType parameters
T
Parameters
valueT- The value to append.
formatstring?- The format to use, or
nullfor the default format. providerIFormatProvider?- The provider to use, or
nullfor the current culture.
AsSpan overloads
AsSpan()
ValueStringBuilder.csReturns the characters written so far, without disposing the builder.
public readonly ReadOnlySpan<char> AsSpan()Returns
AsSpan(int)
ValueStringBuilder.csReturns the characters written so far from start onwards.
public readonly ReadOnlySpan<char> AsSpan(int start)AsSpan(int, int)
ValueStringBuilder.csReturns length characters starting at start.
public readonly ReadOnlySpan<char> AsSpan(int start, int length)Parameters
Returns
Clear()
ValueStringBuilder.csResets ValueStringBuilder.Length to 0, keeping the current buffer. The characters are not erased and stay readable through ValueStringBuilder.RawChars.
public void Clear()Dispose()
ValueStringBuilder.csReleases the buffer back to ArrayPool<T> and resets the builder. Calling it more than once is safe.
public void Dispose()Remarks
The content is not erased; it stays readable by the next consumer to rent the array.
EnsureCapacity(int)
ValueStringBuilder.csGetPinnableReference()
ValueStringBuilder.csReturns a reference to the first character of the buffer, so the builder can be used with a fixed statement. The result is not null-terminated unless ValueStringBuilder.NullTerminate was called.
public ref char GetPinnableReference()Returns
Insert overloads
Insert(int, char, int)
ValueStringBuilder.csInsert(int, string?)
ValueStringBuilder.csNullTerminate()
ValueStringBuilder.csWrites a null character after the content, growing the buffer if needed, without changing ValueStringBuilder.Length.
public void NullTerminate()ToString()
ValueStringBuilder.csReturns the characters written so far and disposes this instance, returning the rented buffer to the pool.
public override string ToString()Returns
Remarks
This method is destructive. After it returns, the builder is reset to its default state: ValueStringBuilder.Length and ValueStringBuilder.Capacity are 0, a second call returns an empty string, and appending starts a new buffer. Use ValueStringBuilder.AsSpan to read the content without disposing the builder.