enum comparison in C#

I’ve been running into a small problem that I can’t figure out.

In one script I declare an class that has a public enum in it.

class a
{
  public enum testValues { TEST1, TEST2 };
}

In another script/class I have a member variable of the same enum type

class b
{
  a.testValues TestValue;
}

Now, when I try to do a comparison such as

  if ( a.testValues.TEST1 == TestValue ) 
  {
    ...
  }

I keep getting an error message that tells me

error CS0266: Cannot implicitly convert type a.testValues' to int’. An explicit conversion exists (are you missing a cast?)

Does anyone know what’s going on here? They are both of the same type. Shouldn’t they compare just fine? I don’t really want to cast here unless it is absolutely necessary.

enumerations are technically just ints, so just put (int) in front of the enum value to cast it

if ((int)a.testValues.TEST1 == TestValue )

Never mind. I found the problem. It was not the comparison. It was the fact that I was using the enum as an array index in the same expression. :wink: