Dictionary Casting
Is it possible to cast an enumerated-key dictionary to an integer-key dictionary? (Or a copy constructor would work fine for what I'm doing as well.) In other words, something that looks like:
Dictionary<int, string> NewDictionary =
(Dictionary<int, string>)OldDictionary<My开发者_开发技巧Enum, string>;
(Yes, I know that syntax isn't quite correct, it's just to show what it is I'm coming from.)
You could iterate over the dictionary and build a new one, transforming each key (e.g. by using the Enumerable.ToDictionary extension) :
OldDictionary.ToDictionary(x => ((int)x.Key, x => x.Value);
精彩评论