我试图将一些VB.net代码转换成C#,并试图将这一行转换出现问题。'Microsoft.Win32.Registry'是一个'类型',但像'变量'一样使用
VB.NET
Dim myreg As Microsoft.Win32.Registry
我知道这是一个静态的,所以我不能创建一个实例,但是当我尝试了VB.NET转换为C#的网站给了我这样的:
Microsoft.Win32.Registry myreg = null;
并给了我一个错误消息:'Microsoft.Win32.Registry'是'类型',但像'变量'一样使用
在VB.NET函数的最后一部分,使用了myreg:
Finally
myreg = Nothing
End Try
这里的整体功能:
Imports System.Data.OleDb
Imports System.Data
Imports Microsoft.Win32.RegistryKey
Imports MyLogger 'custom reference, not worried about this.
Private Function getRegistryString(ByVal sVal As String, Optional ByVal sKey As String = "") As String
Dim myreg As Microsoft.Win32.Registry
Dim s As String
Try
s = myreg.LocalMachine.OpenSubKey(sKey).GetValue(sVal)
Catch ex As Exception
l.EventLog(ex.Message, EventLogEntryType.Error)
Throw ex
Finally
myreg = Nothing
End Try
Return s
s = Nothing
End Function
是那些只引用?你能提供更多关于你如何使用代码的信息吗?这里是.NET注册表类的页面:http://msdn.microsoft.com/en-us/library/microsoft.win32.registry%28v=vs.71%29 – Wug
你从哪里得到VB代码?这很奇怪,至少说*非常*。 –
是的,它是一个前同事代码,大声笑 – nhat