IFixedString Interface
The base interface for a fixed string.
public interface IFixedString : IFormattable, ISpanFormattable- Implements
Properties
| Name | Description |
|---|---|
| Length | Gets the number of characters in the string. The length is always less than or equal to IFixedString.MaxLength. |
| MaxLength | Gets 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
MaxLength
Methods
| Name | Description |
|---|---|
| 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.
Parameters
zeroBufferbooltrueto overwrite the whole underlying buffer with'\0', so the characters that were written can no longer be read throughIFixedString.GetUnsafeFullSpan;falseto only reset the length, asIFixedString.Cleardoes.
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.
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.