Skip to main content
1 of 2
sll
  • 62.7k
  • 22
  • 109
  • 157

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.

sll
  • 62.7k
  • 22
  • 109
  • 157