Reputation: 93
I have the following object:
object {System.Collections.Generic.KeyValuePair<string, object>}
Key is "ipAddresses" string
Value is object[]
where [0] in this array is an object[string]
that I would like to extract. (it's an IP address)
I tried the following code among other things with no success:
object.GetType().Getproperty("ipAddresses")
object.GetType().GetField("ipAddresses")
Note that the object type is: (from watch)
value
{[ipAddresses,System.Object[]]}
Type
object{System.Collections.Generic.KeyValuePair}
I'd like to save value[0]
from the KeyValuePair to a string. Any help would be highly appreciated :)
Upvotes: 2
Views: 3316
Reputation: 9642
object obj; //get key value pair from somewhere
object ips = ((KeyValuePair<string, object>)obj).Value;
string ip = ((object[])ips)[0].ToString();
Upvotes: 2