Public dic0 As New Dictionary(Of String, Func(Of Integer, String))() From { {"ナノメートル", Function(version) "nm"}, {"センチメートル", Function(version) "㎝"}, {"マイクロメートル", Function(version) If(version = 3, "?", "μm")}, {"ミリメートル", Function(version) If(version = 1, "mm", Nothing)} }
Imports Map = System.Collections.Generic.Dictionary(Of String, String) Module Module1 '共通変換テーブル Private dicStandard As New Map() From { {"ナノメートル", "nm"}, {"センチメートル", "㎝"}, {"マイクロメートル", "μm"}, {"ミリメートル", "mm"} } 'バージョン別差分 Private dicDiff As New Dictionary(Of Integer, Map) From { {1, New Map() From {}}, {2, New Map() From {{"ミリメートル", Nothing}}}, {3, New Map() From { {"ミリメートル", Nothing}, {"マイクロメートル", "?"} } } } Public Function Convert(version As Integer, source As String) As String Dim result As String = Nothing If dicDiff(version).ContainsKey(source) Then 'バージョン別差分を優先的に返す Return dicDiff(version)(source) Else 'バージョン別差分に情報が無ければ共通テーブルを使う dicStandard.TryGetValue(source, result) End If Return result End Function End Module