- Home /
Convert returning object to Hashtable
I have a event(from a plugin) which returns an object parameter. When printing the object in console I get System.Collections.Hashtable. So I am guessing the object is a hashtable. How can I convert the object to a hashtable, hence be able to obtain values from keys.
void myEvent(object obj) {
print("object: " + obj);
}
Comment
Best Answer
Answer by hiddenspring81 · May 26, 2013 at 09:19 PM
To convert an Object
into a Hashtable
, use the as
keyword,
void myEvent (object obj){
var hashtable = obj as Hashtable;
// Do stuff with your Hashtable here
}
Note that if your object isn't a Hashtable, your hashtable
variable will be null
, so it may be a good idea to include a null-check before you use it,
void myEvent (object obj){
var hashtable = obj as Hashtable;
if (hashtable == null){
print("It wasn't a Hashtable");
return;
}
// Do stuff with your Hashtable here
}