gpt4 book ai didi

C# - 如何将 KeyValuePair 转换为 KeyValuePair

转载 作者:行者123 更新时间:2023-11-30 20:15:15 25 4
gpt4 key购买 nike

在 C# 中,如何将 KeyValuePair 转换为 KeyValuePair ?我尝试了以下但它不起作用:

public static KeyValuePair<object, object> DoTheCast(KeyValuePair<string, object> the_obj)
{
return (KeyValuePair<object, object>)the_obj;
}

InvalidCastException: Unable to cast object of type 'System.Collections.Generic.KeyValuePair[System.String,System.Object]' to type 'System.Collections.Generic.KeyValuePair[System.Object,System.Object]'.

最佳答案

你不能施放 perse,但是你可以创建一个新的

public static KeyValuePair<object, object> DoTheCast(KeyValuePair<string, object> the_obj)    
=> new KeyValuePair<object, object>(the_obj.Key, the_obj.Value);

关于C# - 如何将 KeyValuePair<string,object> 转换为 KeyValuePair<object,object>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55885888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com