StaticStringMethodCreateTState Method

Creates a new String with a specified length and, once created, initializes it using the specified callback.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static string Create<TState>(
	int length,
	TState state,
	SpanAction<char, TState> action
)

Parameters

length  Int32
The length of the String to be created.
state  TState
The element to be passed to action.
action  SpanActionChar, TState
A callback to initialize the string.

Type Parameters

TState
The type of the element to be passed to action.

Return Value

String
The String created.

Remarks

The method simulates the static method String.Create<TState>(int, TState, SpanAction<char,TState>). In newer .NET versions, the call is forwarded directly to the existing method of the String class. In .NET Framework and .NET Standard 2.0, the simulation makes it possible, when creating short Strings, to have only one heap allocation.

Exceptions

ArgumentNullExceptionaction is null.
ArgumentOutOfRangeExceptionlength is negative.

See Also