Skip to main content
removed xna tag
Link
sll
  • 62.7k
  • 22
  • 109
  • 157

How to compare two Hashtables?(C#)

split the if out
Source Link
Polynomial
  • 28.4k
  • 13
  • 86
  • 110

I am developing a small RTS in C#(with XNA).

I'm setting each unit "goto" position as the vector they should go to. Everything works fine if I don't compare the two Hashtables, but when I do, I get this "NullReferenceException was unhandled" annoying error.

Here's the piece of code I'm getting the error on:

if ( ((float)unit[(int)selectedunits[I+"ID"] + "posX"] !=  (float)cgoto[(int)selectedunits[I+"ID"] + "X"])   &&  ((float)unit[(int)selectedunits[I+"ID"] + "posY"] !=  (float)cgoto[(int)selectedunits[I+"ID"] + "Y"]) ) 

Hopefully this is specific enough.

I am developing a small RTS in C#(with XNA).

I'm setting each unit "goto" position as the vector they should go to. Everything works fine if I don't compare the two Hashtables, but when I do, I get this "NullReferenceException was unhandled" annoying error.

Here's the piece of code I'm getting the error on:

if (((float)unit[(int)selectedunits[I+"ID"] + "posX"] != (float)cgoto[(int)selectedunits[I+"ID"] + "X"])  && ((float)unit[(int)selectedunits[I+"ID"] + "posY"] != (float)cgoto[(int)selectedunits[I+"ID"] + "Y"])) 

Hopefully this is specific enough.

I am developing a small RTS in C#(with XNA).

I'm setting each unit "goto" position as the vector they should go to. Everything works fine if I don't compare the two Hashtables, but when I do, I get this "NullReferenceException was unhandled" annoying error.

Here's the piece of code I'm getting the error on:

if ( ((float)unit[(int)selectedunits[I+"ID"] + "posX"] !=  (float)cgoto[(int)selectedunits[I+"ID"] + "X"])  &&  ((float)unit[(int)selectedunits[I+"ID"] + "posY"] !=  (float)cgoto[(int)selectedunits[I+"ID"] + "Y"]) ) 

Hopefully this is specific enough.

added 8 characters in body
Source Link
Joe
  • 42.9k
  • 20
  • 108
  • 129
Loading
Source Link
Loading