0
지금과 같은 비효율적 인 일을 할 :VB.Net 배열을 통해 어떻게 루프합니까?
' Returns a collection of selected choices in a multichoice field
Dim MyField As NS.ChoiceValues = CType(Me.Form.Fields("Field").Value, NS.ChoiceValues)
If MyField.Choices.Item("Value 1") IsNot Nothing Then
' Do stuff to database choice Value 1, which has id 100
End If
If MyField.Choices.Item("Value 1") Is Nothing Then
' Do other stuff to database choice Value 1, which has id 100
End If
If MyField.Choices.Item("Value 2") IsNot Nothing Then
' Do stuff to database choice Value 2, which has id 200
End If
If MyField.Choices.Item("Value 2") Is Nothing Then
' Do other stuff to database choice Value 2, which has id 200
End If
...
이것은 매우 비효율적이며, 선택의 수가 증가 값 때 읽을된다. 그래서 이것을 업데이트하려고합니다 :
Dim Field1Choices As New Dictionary(Of Integer, String) From {
{100, "Value 1"},
{200, "Value 2"},
{300, "Value 3"},
{400, "Value 4"}
...
}
For Each FieldChoice As String In Field1Choices
If MyField.Choices.Item(var_a) ' var_a should be "Value 1", "Value 2", etc.
DoStuff.WithCoice(Me.Database, "SomeTable", var_b) 'var_b should be 100, 200 etc.
End If
Next
분명히 이것은 작동하지 않습니다. 내 배열에 정수와 문자열이 모두 포함되어 있으므로 For Each FieldChoice As String In Field1Choices
이 작동하지 않습니다.
var_a
및 var_b
이 배열 값의 값을 가져 오도록 Field1Choices 배열을 반복 할 수 있습니까?
사전 적은 키 - 값 쌍을 포함'(정수, 문자열) KeyValuePair 각 FieldChoice에 들어 Field1Choices' 그러면 'FieldChoice.Key'와'FieldChoice.Value'와 같은 키/값을 얻을 수 있습니다. –