This documentation is archived and is not being maintained.

RegistryKey.ToString Method

Retrieves a string representation of this key.

[Visual Basic]
Overrides Public Function ToString() As String
[C#]
public override string ToString();
[C++]
public: String* ToString();
[JScript]
public override function ToString() : String;

Return Value

A string representing the key. If the specified key is invalid (cannot be found) then a null value is returned.

Exceptions

Exception Type Condition
ObjectDisposedException The RegistryKey being accessed is closed (closed keys cannot be accessed).

Remarks

The return value includes the registry path of the specified key, and the hexadecimal value for the key. The registry path includes the absolute root of the specified key, always starting at one of the base keys for the registry (for example, HKEY_LOCAL_MACHINE).

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the RegistryKey class.

[Visual Basic] 
' Delete or close the new subkey.
Console.Write(vbCrLf & "Delete newly created " & _
    "registry key? (Y/N) ")
If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"C Then
    Registry.CurrentUser.DeleteSubKeyTree("Test9999")
    Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _
        test9999.Name)
Else
    Console.WriteLine(vbCrLf & "Registry key {0} closed.", _
        test9999.ToString())
    test9999.Close()
End If

[C#] 
// Delete or close the new subkey.
Console.Write("\nDelete newly created registry key? (Y/N) ");
if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y')
{
    Registry.CurrentUser.DeleteSubKeyTree("Test9999");
    Console.WriteLine("\nRegistry key {0} deleted.", 
        test9999.Name);
}
else
{
    Console.WriteLine("\nRegistry key {0} closed.", 
        test9999.ToString());
    test9999.Close();
}

[C++] 
// Delete or close the new subkey.
Console::Write(S"\nDelete newly created registry key? (Y/N) ");
if(Char::ToUpper(Convert::ToChar(Console::Read())) == 'Y')
{
    Registry::CurrentUser->DeleteSubKeyTree(S"Test9999");
    Console::WriteLine(S"\nRegistry key {0} deleted.", 
        test9999->Name);
}
else
{
    Console::WriteLine(S"\nRegistry key {0} closed.", 
        test9999->ToString());
    test9999->Close();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RegistryKey Class | RegistryKey Members | Microsoft.Win32 Namespace | Name

Show: