いくつかの VB.net コードを C# に変換しようとしていますが、この 1 行を変換しようとすると問題が発生します。
VB.NET
Dim myreg As Microsoft.Win32.Registry
私はそれが静的であることを知っているので、インスタンスを作成することはできませんが、C# への VB.NET コンバーターを試してみると、Web サイトで次のように表示されます。
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