Witam serdecznie. mam obiekt controller
oraz event
. Pobieram listę List<controller> controllers
i List<event> events
. w klasie event mam pole controllerID
. Jak połączyć te obie kolekcje w Dictionary<controller, event[]>
?
Próbowałem tak, ale niestety jak jakiś kontroler został usunięty to wyszukiwanie da mi null, co spowoduje wyjątek podczas tworzenia słownika.
//GetEventsHistory zwraca wszystkie zdarzenia event[]
//FindControllerById zwraca kontroler o podanym Id lub null, jeżeli nie znaleziono
Dictionary<controller, event[]> dict = GetEventsHistory()
.GroupBy(x => x.ControllerID)
.ToDictionary(x => FindControllerById(x.Key), x => x.ToArray());