c# - C# - 我如何转换 KeyValuePair到键值对
问题描述
在 C# 中,如何将KeyValuePair<string, object>转换为KeyValuePair<object, object>?我尝试了以下方法,但它不起作用:
public static KeyValuePair<object, object> DoTheCast(KeyValuePair<string, object> the_obj)
{
return (KeyValuePair<object, object>)the_obj;
}
InvalidCastException:无法将“System.Collections.Generic.KeyValuePair[System.String,System.Object]”类型的对象转换为“System.Collections.Generic.KeyValuePair[System.Object,System.Object]”类型。
解决方案
您将无法施放pers,但您可以创建一个新的
public static KeyValuePair<object, object> DoTheCast(KeyValuePair<string, object> the_obj)
=> new KeyValuePair<object, object>(the_obj.Key, the_obj.Value);
推荐阅读
- c - 不明白为什么 head = head->next 有效
- matlab - 在 Octave|MATLAB 中生成单位三角矩阵
- java - 克拉纳颤抖着
- python-3.x - Python imaplib 模块 - 如何以 (GMT-06:00) 中部时间(美国和加拿大)格式提取日期
- python - Tensorflow 对象检测训练失败,因为 int() 以 10 为底的无效文字:“{num_steps}”。将 var 读取为字符串而不是 int
- javascript - 将卡片元素大小固定为相同的 html+Scss+javascript
- math - 什么是 (sqrt(1+8*long(num)) - 1)/2?
- swift - 'GDTCORLibrary/Public/GDTCORTransport.h' 文件未找到
- javascript - 添加标签时图表JS中的极地区域旋转
- sql - 需要基于某些条件的sql查询