'Cannot implicitly convert type void to microsoft.win32.registrykey

Error: cannot implicitly convert type void to microsoft.win32.registrykey

Code:

using Microsft.Win32;
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Sofware",true).DeleteSubKey("TEST");

But for some reason this code works:

using Microsft.Win32;
RegistryKey key1 = Registry.CurrentUser.OpenSubKey(@"Sofware", true).CreateSubKey("TEST");


Solution 1:[1]

Looking at the signature of DeleteSubKey here It says it is void, hence it returns nothing and cannot be assigned to RegistryKey. Call the function without using its return value

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mati.o