C# 如何通过在c中指定名称来读取注册表项值

C# 如何通过在c中指定名称来读取注册表项值,c#,registry,C#,Registry,我正在向我的Windows注册表中写入一个值。现在根据我的要求,我必须读取它,而不指定保存它的路径名,但我不知道如何检索它。 下面是要编写的代码 Microsoft.Win32.RegistryKey exampleRegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("ExampleTest"); exampleRegistryKey.SetValue("Conn", "Connectio

我正在向我的Windows注册表中写入一个值。现在根据我的要求,我必须读取它,而不指定保存它的路径名,但我不知道如何检索它。 下面是要编写的代码

        Microsoft.Win32.RegistryKey exampleRegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("ExampleTest");
        exampleRegistryKey.SetValue("Conn", "Connection Test");
        exampleRegistryKey.Close();
请帮我看一下这把钥匙。 谢谢


使用以下方法按注册表项的名称获取注册表项的值:

   public static string PathName
     { 
      get
         {
          RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\ExampleTest")
          string registryContent = (Registry.GetValue(registryKey.Name, "Con", "not exist")).ToString();
          return registryContent;  
         }
     }

如果在注册表中找不到Con值,将返回文本not exist。

get和set通常成对出现…@eddie_cat Ok你能从我的代码中告诉我需要如何继续吗?阅读此问题@eddie_cat请根据您的指示查看我的更新帖子,其中包含经过尝试的代码,并告诉我哪里错了,因为我没有得到值。。
   public static string PathName
     { 
      get
         {
          RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\ExampleTest")
          string registryContent = (Registry.GetValue(registryKey.Name, "Con", "not exist")).ToString();
          return registryContent;  
         }
     }