MaskedTextProvider.ToString Method (Boolean, Boolean, Int32, Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Returns a substring of the formatted string, optionally including prompt and literal characters.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public string ToString(
	bool includePrompt,
	bool includeLiterals,
	int startPosition,
	int length


Type: System.Boolean

true to include prompt characters in the return string; otherwise, false.

Type: System.Boolean

true to include literal characters in the return string; otherwise, false.

Type: System.Int32

The zero-based position in the formatted string where the output begins.

Type: System.Int32

The number of characters to return.

Return Value

Type: System.String

If successful, a substring of the formatted String, which includes all the assigned character values and optionally includes literals and prompts; otherwise the Empty string.

This version of the overloaded ToString method returns a substring of the formatted string, starting at the position startPos and including the subsequent number of characters specified by the length parameter. The return string includes prompts and literals according to the values of the IncludePrompt and IncludeLiterals parameters, respectively. Notice that these parameters override the values of the IncludePromptIncludeLiterals properties. This method will always return the original input characters, ignoring the value of the PasswordChar property.


Because this method reveals information that is usually protected in the user interface by password characters, it should be used with extreme caution to avoid accidentally revealing sensitive user data.

ToString performs the following actions when there are discrepancies in the input parameters:

  • If startPos is less than zero, the starting position is set to zero.

  • If startPos is greater than or equal to the actual Length of the formatted string, the Empty string is returned.

  • If length is greater than the remaining number of characters past the starting position, only the remaining characters are returned.

  • If length is less than or equal to zero, the Empty string is returned.

.NET Framework
Available since 2.0
Return to top