, 당신은 두 개의 사전을 함께 스티치 Zip를 사용할 수있는 사전의 순서와 길이를 가정 :
Sub Main
Dim sb = New StringBuilder()
Dim DicMonth = New Dictionary(Of String, Integer)() From { _
{"Jan", 674}, _
{"Feb", 635} _
}
Dim DicMeetTotal = New Dictionary(Of String, Integer)() From { _
{"Jan", 670}, _
{"Feb", 631} _
}
Dim lineStrings = DicMonth.Zip(DicMeetTotal, _
Function(m, mt) String.Format("{0} {1} Meet {2} Missed {3}", _
m.Key, m.Value, mt.Value, m.Value - mt.Value))
For Each ls In lineStrings
sb.AppendLine(ls)
Next
Console.WriteLine(sb.ToString())
End Sub
다른 방법으로 조인 키가있는 경우 (예 : dicti onaries) 동일합니다, 당신과 같이 함께 Linq에 Join을 사용할 수 있습니다 : 각 단지 하나의 값을 포함하는 N 다른 사전을 모델로 한하지 않을 것이라고 가정
Dim lineStrings = DicMonth.Join(DicMeetTotal, _
Function(m) m.Key, Function(mt) mt.Key, _
Function(m, mt) String.Format("{0} {1} Meet {2} Missed {3}", _
m.Key, m.Value, mt.Value, m.Value - mt.Value))
편집
을 (이 여전히 보유)
Class MeetTotalEntity
Public Property Meet As Integer
Public Property Missed As Integer
Public Property Cancel As Integer
Public Property Other As Integer
End Class
를, 그리고, 우편 번호를 (또는 가입 : 엔티티의 라인 가치, IMO 속성에 따라) 모델링 오류 것, 당신이 엔티티는 데이터를 보유 할 것 같은데요. 두 번째 사전의 Value
에는 위의 엔티티가 포함되어 있으므로 적절하게 필드를 참조 해제하십시오.
Sub Main
Dim sb = New StringBuilder()
Dim DicMonth = New Dictionary(Of String, Integer)() From { _
{"Jan", 674}, _
{"Feb", 635} _
}
Dim DicMeetTotal = New Dictionary(Of String, MeetTotalEntity)() From { _
{"Jan", New MeetTotalEntity With {.Meet = 670, .Missed = 4, .Cancel = 10, .Other = 5}}, _
{"Feb", New MeetTotalEntity With {.Meet = 631, .Missed = 10, .Cancel = 3, .Other = 2}} _
}
Dim lineStrings = DicMonth.Zip(DicMeetTotal, _
Function(m, mt) String.Format("{0} Total {1} Meet {2} Missed {3} Cancel {4} Other {5}", _
m.Key, m.Value, mt.Value.Meet, mt.Value.Missed, mt.Value.Cancel, mt.Value.Other))
For Each ls In lineStrings
sb.AppendLine(ls)
Next
Console.WriteLine(sb.ToString())
End Sub
AppenLine은 무엇을합니까? – CheGueVerra
"missed"의 값은 어디에서 왔습니까? (또는 둘 사이의 차이 일뿐입니다) 모든 사전의 키가 월입니까? 그리고 사전은 키 값 쌍의 수가 같은가요? – StuartLC