Tech Off Thread

1 post

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);

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.