RegistryKey.Close Method

Definition

Closes the key and flushes it to disk if its contents have been modified.

C#
public void Close();

Examples

This code example is part of a larger example provided for the RegistryKey class.

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

Remarks

Calling this method on system keys will have no effect, because system keys are never closed.

This method does nothing if you call it on an instance of RegistryKey that is already closed.

Applies to

Toode Versioonid
.NET 6, 7, 8, 9, 10
.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
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5

See also