From Evernote: |
[.NET]Hashテーブル(辞書)を使ったクラス |
Hashテーブル(dictionary型)を使ったクラスを持っておいて
1度宣言すれば
ループ時等で何度もマスタ読みに行かなくてラク。
'本文では==================================
Dim GetTanto As New GetTanto '宣言
Dim TestArray(3) = {1000,2000,3000}
For i As Integer = 0 To TestTrray.Length - 1
debug GetTanto.GetName(TestArray(i)) '表示
Next
'クラスは=======================================
'class_担当者をとってくる -------
Public Class GetTanto
# Region "Member"
Private NameTBL As New System.Collections.Generic.Dictionary(Of Integer , String)
# End Region
# Region "Constructor"
Sub New ()
MyClass.ReadMaster()
End Sub
# End Region
# Region "ReadMaster"
Sub ReadMaster()
Dim strSQL As String = "SELECT * from M_ 担当者"
Dim objDS As New DataSet
ADONET.FillDataset(STRCON, objDS, "Table" , strSQL)
For i As Integer = 0 To objDS.Tables("Table").Rows.Count - 1
With objDS.Tables("Table").Rows(i)
NameTBL.Add(.Item( "担当コード "), .Item( "担当者"))
End With
Next
End Sub
# End Region
# Region "GetName"
Public Function GetName( ByVal No As Object) As String
Dim tmp As String = ""
'合致するなら
If NameTBL.ContainsKey(No) Then
tmp = NameTBL(No).ToString.Trim
End If
Return tmp
End Function
# End Region
End Class