Convert Generic Dictionary to different type

后端 未结 4 545
無奈伤痛
無奈伤痛 2021-01-17 13:02

Is there a quick way to convert a Generic Dictionary from one type to another

I have this

IDictionary _commands;
4条回答
  •  不要未来只要你来
    2021-01-17 13:40

    I suppose I would write

    Handle(_commands.ToDictionary(p => p.Key, p => (object)p.Value));
    

    Not the most efficient thing in the world to do, but until covariance is in, that's the breaks.

提交回复
热议问题