我有以下对象:
object {System.Collections.Generic.KeyValuePair<string, object>}
键是“ipAddresses”字符串
值为 object[]
其中此数组中的 [0] 是一个对象[string]
我想提取的。 (这是一个IP地址)
我尝试了以下代码,但没有成功:
object.GetType().Getproperty("ipAddresses")
object.GetType().GetField("ipAddresses")
请注意,对象类型是:(来自 watch )
值
{[ipAddresses,System.Object[]]}
类型
对象{System.Collections.Generic.KeyValuePair}
我想保存value[0]
从 KeyValuePair 到字符串。任何帮助将不胜感激:)
最佳答案
object obj; //get key value pair from somewhere
object ips = ((KeyValuePair<string, object>)obj).Value;
string ip = ((object[])ips)[0].ToString();
关于c# - 如何从对象 {System.Collections.Generic.KeyValuePair<string, object> 中提取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54671662/