IFixedString Interface

The base interface for a fixed string.

public interface IFixedString : IFormattable, ISpanFormattable
Implements

Properties

NameDescription
LengthGets the number of characters in the string. The length is always less than or equal to IFixedString.MaxLength.
MaxLengthGets the maximum number of characters in this fixed string.

Length

Gets the number of characters in the string. The length is always less than or equal to IFixedString.MaxLength.

int Length { get; }

Property value

int

MaxLength

Gets the maximum number of characters in this fixed string.

public static abstract int MaxLength { get; }

Property value

int

Methods

NameDescription
Clear()Resets this string to an empty string.
Clear(bool)Resets this string to an empty string, optionally overwriting the underlying buffer with zeros.
GetUnsafeFullSpan()Returns a span of all the characters up to IFixedString.MaxLength.

Clear overloads

Clear()

Resets this string to an empty string.

void Clear()
Remarks

Only the length is reset. The characters that were written are not overwritten: they stay in the underlying buffer and remain readable through IFixedString.GetUnsafeFullSpan. Do not rely on this method to erase sensitive data.

Clear(bool)

Resets this string to an empty string, optionally overwriting the underlying buffer with zeros.

void Clear(bool zeroBuffer)
Parameters
zeroBuffer bool
true to overwrite the whole underlying buffer with '\0', so the characters that were written can no longer be read through IFixedString.GetUnsafeFullSpan; false to only reset the length, as IFixedString.Clear does.
Remarks

The whole buffer is overwritten, not only the characters up to IFixedString.Length: a previous longer value can still be present after IFixedString.Length.

GetUnsafeFullSpan()

Returns a span of all the characters up to IFixedString.MaxLength.

unsafe Span<char> GetUnsafeFullSpan()

Returns

Span<char> A span of characters that contains the characters of this string.

Remarks

This method is unsafe: the returned span is not tied to the lifetime of the struct, so the compiler cannot prevent it from outliving the struct. The caller must not use the span after the struct goes out of scope (for instance, it must not return the span of a local variable). Favor using AsSpan() on individual FixedStrings structs.

This method requires an unsafe context (an unsafe block or expression) when the calling code is compiled with the updated memory safety rules.

This method can only be used through a generic constraint or by explicit casting/boxing to IFixedString.