1 Static voidMain (string[] args)2 {3 //cannot start with \ or return null4RegistryKey RK = Registry.CurrentUser.OpenSubKey (@"\software");5Console.WriteLine (RK = =NULL);//true6 7RK = Registry.CurrentUser.OpenSubKey (@"Software");8Console.WriteLine (RK = =NULL);//false9 TenRK = Registry.CurrentUser.OpenSubKey (@"Software\adobe"); OneConsole.WriteLine (RK. Name);//Hkey_current_user\software\adobe A -RK = Registry.CurrentUser.OpenSubKey (@"Software\adobe"); -Console.WriteLine (RK = =NULL);//false the - //value does not exist, no default value is specified, NULL is returned - ObjectObj1 = rk. GetValue ("X2009"); -Console.WriteLine (obj1 = =NULL);//true + - //item does not exist return null +RK = Registry.CurrentUser.OpenSubKey (@"software\x2009"); AConsole.WriteLine (RK = =NULL);//true at - //-------------------------------------------------- - - //item exists, value does not exist, return default value - Objectobj = Registry.getvalue (@"Hkey_current_user\software\adobe","KEY","VALUE"); -Console.WriteLine ((string) obj = ="VALUE");//true in - //item does not exist return null toobj = Registry.getvalue (@"hkey_current_user\software\x2009","KEY","VALUE"); +Console.WriteLine (obj = =NULL);//true - the //-------------------------------------------------- * $ //Software\adobe\iac entry exists, subkey does not existPanax NotoginsengRK = Registry.CurrentUser.OpenSubKey (@"Software\adobe\iac"); -Console.WriteLine (RK = =NULL);//false the string[] arr =RK. Getsubkeynames (); +Console.WriteLine (arr = =NULL);//false AConsole.WriteLine (arr. Length = =0);//true the + //traversing an empty array without error - string[] ss =New string[0]; $ foreach(stringSinchSS) { } $ - //traversing a null array will cause an error -SS =NULL; the //foreach (string s in ss) {}//System.NullReferenceException - Wuyi //Summary: the //OpenSubKey Open subkey cannot start with \ - //OpenSubKey, Registry.getvalue, RegistryKey.GetValue returns NULL when its entry does not exist Wu //Registry.getvalue Returns a default value or NULL when its value does not exist - //the above two can determine whether the key or value of the registry exists About //Getsubkeynames returns an empty array instead of NULL when the subkey does not exist $ - console.readline (); -}
C # Registry keys and values are empty tests