SecureString.MakeReadOnly Method ()

 

Makes the text value of this secure string read-only.

Namespace:   System.Security
Assembly:  mscorlib (in mscorlib.dll)

member MakeReadOnly : unit -> unit

Exception Condition
ObjectDisposedException

This secure string has already been disposed.

Initialize the text value of an instance of the SecureString class with the SecureString constructors, and modify the value with the Clear, RemoveAt, SetAt, InsertAt, and AppendChar methods.

After you have made your final modifications, use the MakeReadOnly method to make the value of the instance immutable (read-only). After the value is marked as read-only, any further attempt to modify it throws an InvalidOperationException.

The effect of invoking MakeReadOnly is permanent because the SecureString class provides no means to make the secure string modifiable again. Use the IsReadOnly method to test whether an instance of SecureString is read-only.

The following example demonstrates how the AppendChar and RemoveAt methods can be used to collect the characters in a password. After the password is collected, it is made read-only.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: