Convert Generic Dictionary to different type

后端 未结 4 548
無奈伤痛
無奈伤痛 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

    maybe this function can be useful for you

    IEnumerable> Convert(IDictionary dic) {
        foreach(var item in dic) {
            yield return new KeyValuePair(item.Key, item.Value);
        }
    }
    

    And you will call it like so:

    Handle(Convert(_commands));
    

提交回复
热议问题