When I save the value of this Hastable
it gives me error.
Follow the code:
Hashtable ht = new Hashtable();
ht.Add("index", index);
ht.Add("tipo", "1");
string tipo = ht["tipo"];
When I save the value of this Hastable
it gives me error.
Follow the code:
Hashtable ht = new Hashtable();
ht.Add("index", index);
ht.Add("tipo", "1");
string tipo = ht["tipo"];
When you return a value from a Hastable you have to convert it to String like this:
string tipo = ht["tipo"].ToString();
First, do not use this data structure, it is considered obsolete and should no longer be used by any application. Instead, Dictionary<K, V>
. Once this is done, the problem will not occur. If you insist you will have performance problems and errors of this type, which can even be solved (doing conversion, for example), but not worth the effort.
var ht = new Dictionary<string, string>();
ht.Add("index", "0");
ht.Add("tipo", "1");
string tipo = ht["tipo"];
See running on dotNetFidle and on CodingGround .