요소를 추가 할 ConcurrentDictionary가 있습니다.ConcurrentDictionary 값을 키로 반복
키가 고유하지 않으며 여러 값을 반영 할 수 있습니다.
- 는 내가 다음에 "다음"문에 값
- 컴파일러 충돌의 목록을 얻으려면 키를 기준으로 값을 반복
- 그들의 고유 한 이름을 얻기 위해 키를 반복 오류 :
Additional information: Conversion from string "LOS ANGELES" to type 'Integer' is not valid.
그래서, 난 (문자열의) 키가 있다면, 어떻게 그 키와 관련된 값을받을 수 있나요?
Dim dict As New ConcurrentDictionary(Of String, String)
dict.TryAdd("LOS ANGELES", "black")
dict.TryAdd("LOS ANGELES", "yellow")
dict.TryAdd("LOS ANGELES", "blue")
dict.TryAdd("LOS ANGELES", "orange")
dict.TryAdd("LOS ANGELES", "yellow")
dict.TryAdd("LOS ANGELES", "yellow")
dict.TryAdd("LOS ANGELES", "yellow")
dict.TryAdd("LOS ANGELES", "yellow")
dict.TryAdd("LOS ANGELES", "orange")
For Each stKeys As String In dict.Keys
If stKeys <> Nothing Then
For Each values In dict.Values(stKeys)
If values <> Nothing Then
Debug.Print(values.ToString)
End If
Next
End If
Next
UPDATE :
나는 ConcurrentDictionary 대신 잠금과, 그것에 구조를 전달 목록을 사용하고, 그 말에, 나는에 해당 항목을 분류 : 나는 문제를 해결하는 방법 다음과 같이 NameValueCollection :
Structure structCities
CityName as String
vColor as string
End Structure
DIM dataList as new List(of structCities)
DIM vData as new structCities
with vData
.CityName = "LOS ANGELES"
.vColor = "black"
end with: dataList.add(vData)
with vData
.CityName = "LOS ANGELES"
.vColor = "black"
end with: dataList.add(vData)
with vData
.CityName = "LOS ANGELES"
.vColor = "black"
end with: dataList.add(vData)
with vData
.CityName = "LOS ANGELES"
.vColor = "black"
end with: dataList.add(vData)
with vData
.CityName = "LOS ANGELES"
.vColor = "yellow"
end with: dataList.add(vData)
Dim dict As New NameValueCollection
For Each c In dataList
dict.Add(c.CityName, c.vColor)
Next
코드는 사전의 첫 번째 항목 만 저장합니다 (LOS ANGELES, "black"). TryAdd에 대한 다른 모든 호출은'LOS ANGELES '키가 이미 존재하기 때문에'false'를 반환합니다. – Jehof
것은 첫 번째 값을 저장하는 것이 아닙니다. dict.values () 위로 마우스를 가져 가면 문제없이 모든 값을 반환하지만 키가 고유해야한다는 점에서 옳은 것입니다. – Matth3w
그래서 ConcurrentDictionary (비 고유 키 포함)에서 List로 갔습니까? – Paparazzi