Jam*_*ord 2 vb.net visual-studio-2013
我有一个winform,它将注册数据保存到注册表中的"Ddoe" - 但是我需要检查该值是否先前已设置(创建),这样做我试图这样做:
If (Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\FCRA\Assignment").GetValue("Ddoe") Is Nothing Then
'doesnt exist
else
'exists
end if
Run Code Online (Sandbox Code Playgroud)
但这不能正常运作
我收到一个错误
An unhandled exception of type 'System.NullReferenceException' occurred in #appname
Run Code Online (Sandbox Code Playgroud)
它在if语句行显示此错误
有没有更好的方法来检查这个注册表项的存在或我是否会这样做是错的
我认为问题是,"HKEY_CURRENT_USER\SOFTWARE\FCRA \分配"不存在,所以OpenSubKey回报Nothing.您不能对Nothing值使用任何方法.试试这个:
If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\FCRA\Assignment",
"Ddoe", Nothing) Is Nothing Then
'value does not exist
End If
Run Code Online (Sandbox Code Playgroud)
取自这里:
| 归档时间: |
|
| 查看次数: |
4267 次 |
| 最近记录: |