C # registry key and value NULL test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.