[Mono-list] Enum.Equals() confusion

Nick Drochak ndrochak@gol.com
Mon, 18 Mar 2002 01:27:04 +0900


Hi.

I'm a bit confused about Enum.Equals().  Consider this code (adapted
from a unit test)

enum TestingEnum {This, Is, A, Test};
enum TestingEnum2 {This, Is, A, Test};
...
Enum e1 = new TestingEnum();
Enum e2 = new TestingEnum();
Enum e3 = new TestingEnum2();

bool b1 = e1.Equals(e2);
bool b2 = e1.Equals(e3);
bool b3 = TestingEnum.Test.Equals(TestingEnum2.Test);

From the docs I know that b3 should be false.  

However, should b1 and b2 should also be false? I would think so,
because the Equals method should check that the operands are referring
to the same object, which they are not.  This is confusion part 1.

Part 2 is this: What is the difference between the Equals that is called
on e1 and the Equals called on Testing.Test?  Enum.Equals() should try
to get the underlying values to compare them, but can you get a value of
the enum object like e1?  Does anyone know what I am talking about?

Short of an explanation, please just fix the Enum class so that the unit
test passes :)  I'll look at the code and see the answer. You can build
RunTests.corlib.exe from 'make test' and run it with the jit.  You'll
see the error there.

Regards and good night,
Nick D.