how do I (aggregate ?) two dictionaries ?
I have the following code :
private Dictionary
private Dictionary
agents = (from a in log.InitialState.Agents.Agent
select a).ToDictionary(d => Convert.ToInt32(d.id), d => d as aor.PhysicalObject);
objects = (from o in log.InitialState.Objects.Object
select o).ToDictionary(d => Convert.ToInt32(d.id), d => d as aor.PhysicalObject);
what I want now, is ONE dictionary containing all elements of the agents & objects dictionary. You may
think that there could be a problem with duplicate keys, but each key (id) is unique, so there will be no
problem.
Would be very cool, if this task could be done via only one LINQ query (like the above... just "put together").
Many thanks in advance :-)
bye
paddy3k
AlanPosted Oct 20, 2008, 5:55 AM
Provided the keys are unique you could combine the two dictionaries as follows:
private Dictionary merger;
merger = Enumerable.Concat(from a in log.InitialState.Agents.Agent
select a, from o in log.InitialState.Objects.Object select o).ToDictionary(d => Convert.ToInt32(d.id), d => d as aor.PhysicalObject);