There are not problems in hashtable values comparision you've provided. There some issues with casting and some general design points. I believe you got such exception when trying to cast null to float/int, to avoid such casesissues use Hashtable.ContainsKey() method to check whether a given key exist in thea hashtable and only then acces it's value and check it. Do not forget checking a value for null before cast. Also you can consider using generic typed IDictionary<string, float> (see MSDN) so all values would be typed and you do not need to cast explicitly, this also would give some perfromance gains since no more boxing for value types like in your example float -> object when store a value and object -> float (unboxing) when retrieve back and cast.
There are not problems in hashtable values comparision you've provided. There some issues with casting and some general design points. I believe you got such exception when trying to cast null to float, to avoid such cases use Hashtable.ContainsKey() method to check whether a given key in the hashtable and only then acces it's value and check it for null before cast. Also you can consider using generic typed IDictionary<string, float> (see MSDN) so all values would be typed and you do not need to cast explicitly, this also would give some perfromance gains since no more boxing for value types like in your example float -> object when store a value and object -> float (unboxing) when retrieve back and cast.
There are not problems in hashtable values comparision you've provided. There some issues with casting and some general design points. I believe you got such exception when trying to cast null to float/int, to avoid such issues use Hashtable.ContainsKey() method to check whether a given key exist in a hashtable and only then acces it's value. Do not forget checking a value for null before cast. Also you can consider using generic typed IDictionary<string, float> (see MSDN) so all values would be typed and you do not need to cast explicitly, this also would give some perfromance gains since no more boxing for value types like in your example float -> object when store a value and object -> float (unboxing) when retrieve back and cast.
There are not problems in hashtable values comparision you've provided. There some issues with casting and some general design points. I believe you got such exception when trying to cast null to float, to avoid such cases use Hashtable.ContainsKey() method to check whether a given key in the hashtable and only then acces it's value and check it for null before cast. Also you can consider using generic typed IDictionary<string, float> (see MSDN) so all values would be typed and you do not need to cast explicitly, this also would give some perfromance gains since no more boxing for value types like in your example float -> object when store a value and object -> float (unboxing) when retrieve back and cast.