Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace MyNameSpace
{
public enum MyEnum : int
{
MyEnumValue1 = 1,
MyEnumValue2 = 2
}
public class MyClass
{
void MyClassMethod(int SomeInteger)
{
// do something
}
void CallMyClassMethodWrong()
{
// Next line generates two compiler errors
MyClassMethod(MyEnum.MyEnumValue1);
}
void CallMyClassMethodRight()
{
// Next line generates no errors
MyClassMethod((int)MyEnum.MyEnumValue2);
}
}
}
the code above generates two errors on the same line (Visual Studio 2005):
Error 2 The best overloaded method match for 'MyNameSpace.MyClass.MyClassMethod(int)' has some invalid arguments
Error 3 Argument '1': cannot convert from 'MyNameSpace.MyEnum' to 'int'
Of course casting takes away the errors, but I wonder why is this? Is an enum : int not considered to be an int?
Marcel