RegistryKey.ToString 方法

定義

擷取這個機碼的字串表示。

C#
public override string ToString ();

傳回

表示機碼的字串。 如果指定的機碼是無效的 (找不到),則會傳回 null 值。

例外狀況

正接受存取的 RegistryKey 已經關閉 (關閉的機碼無法存取)。

範例

此程式代碼範例是針對 類別提供的較大範例的 RegistryKey 一部分。

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();
}

備註

傳回值包含指定機碼的登錄路徑,以及索引鍵的十六進位值。 登錄路徑包含指定密鑰的絕對根目錄,一律從登錄的其中一個基底機碼開始,例如,HKEY_LOCAL_MACHINE。

適用於

產品 版本
.NET Core 1.0, Core 1.1, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5

另請參閱