각 머리글에 머리글 제목과 일치하는 개체 목록이 있도록 머리글 아래에 linq 쿼리의 항목을 그룹화합니다. 나는 솔루션이 ToDictionary를 사용하여 객체를 변환하는 것으로 가정했으나 "그룹"(또는 사전 키) 당 하나의 객체 만 허용합니다. 나는 (String, List Of()) 유형의 사전을 만들 수 있다고 가정했으나 그것을 작성하는 방법을 알 수 없다.Linq ToDictionary를 사용하여 사전 항목에 여러 값이있는 사전을 반환하려면 어떻게해야합니까?
예를 들어 아래에 단순화 된 버전을 작성했습니다. 내가 출력 어떻게해야합니까
'Public Function ConvertOrderToArray(myVal As order, myList As System.Collections.Generic.List(Of order)) As System.Collections.Generic.List(Of order)'
does not have a signature compatible with delegate
'Delegate Function Func(Of order, System.Collections.Generic.List(Of order))(arg As order) As System.Collections.Generic.List(Of order)'.
각 사전 항목에 대한 목록을 다음과 같이
Public Class order
Public ID As Integer
Public Name As String
Public DateStamp As Date
End Class
Public Function GetOrdersSortedByDate() As Generic.Dictionary(Of String, Generic.List(Of User))
Dim orders As New List(Of order)(New order() _
{New order With _
{.ID = 1, .Name = "Marble", .DateStamp = New Date(2010, 1, 1)}, _
New order With _
{.ID = 2, .Name = "Marble", .DateStamp = New Date(2010, 5, 1)}, _
New order With _
{.ID = 3, .Name = "Glass", .DateStamp = New Date(2010, 1, 1)}, _
New order With _
{.ID = 4, .Name = "Granite", .DateStamp = New Date(2010, 1, 1)}})
' Create a Dictionary that contains Package values,
' using TrackingNumber as the key.
Dim dict As Dictionary(Of String, List(Of order)) = _
orders.ToDictionary(Of String, List(Of order))(Function(mykey) mykey.Name, AddressOf ConvertOrderToArray) ' Error on this line
Return dict
End Function
Public Function ConvertOrderToArray(ByVal myVal As order, ByVal myList As Generic.List(Of order)) As Generic.List(Of order)
If myList Is Nothing Then myList = New Generic.List(Of order)
myList.Add(myVal)
Return myList
End Function
오류는?
Dim f = d.GroupBy (Function (x) x.PoolName) .ToDictionary (Function (t) t.Key, Function (g) g.ToList()) - 가보 겠어! – digiguru
이것은 마치 꿈처럼 작동했습니다. 감사합니다. – digiguru