Tech Off Thread

1 post

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Can you swap nested dictionaries keys in LINQ without taking huge perf hit?

Back to Forum: Tech Off
  • User profile image

    My current code is this. Of course I could write some other code so that this isn't even needed but regardless I'm interested in how to do this in LINQ while preserving similar perf.

            private static void SwapDictKeys(Dictionary<DateTime, Dictionary<MyKey, MyValue>> dorg, Dictionary<MyKey, Dictionary<DateTime, MyValue>> dswp)
                foreach (var dt in dorg)
                    foreach (var mval in dt.Value)
                        Dictionary<DateTime, MyValue> dhlp;
                        if (!dswp.TryGetValue(mval.Key, out dhlp)) { dhlp = new Dictionary<DateTime, MyValue>(); dswp.Add(mval.Key, dhlp); }
                        dhlp.Add(dt.Key, mval.Value);

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.